Magento 1 – How to Show All Product Images in Product Listing

magento-1product-images

I want to show all product images in product listing page(list.phtml file).

So to do so I've done following in list.phtml

var_dump($_product->getMediaGalleryImages());

But it returns with NULL.

Another way I found is as following

$mediaApi = Mage::getModel('catalog/product_attribute_media_api');
$mediaItems = $mediaApi->items($_product->getId());
foreach ($mediaItems as $image) {
    echo $image['file'] ."<br>";
}

But it return me half path like
/p/a/pawo.jpg.

So is there any better way to get all product images(Gallery) in product listing page??

NOTE : I also need to resize image like we do as following.

 <img id="product-image-<?php echo $_product->getId(); ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(TRUE)->keepAspectRatio(FALSE)->keepFrame(FALSE)->resize($_imgSize,$_imgSize); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>

Best Answer

You can try below code. You canget path using catalog helper

echo Mage::helper('catalog/image')->init($_product, 'image', $image['file']) ."<br>";

From this code you can get cache path also.

Related Topic