How to display all product images on magento

dutycorpse picture dutycorpse · Mar 3, 2014 · Viewed 18.3k times · Source

I try to display all image in product page like this

I have a loop like this:

<?php                                                                   
          foreach ($_product->getData('media_gallery')['images'] as $image)  
          {                                                                     
            echo '<img src="' . $image['file'] . '" />';                                                                                                                                                                                     
          }                                                                     
?> 

The link isn't the right path and I don't know how to find the right one.

Does anyone have an idea ?

Thanks.

Answer

Shivam picture Shivam · Mar 3, 2014

try below code

$product = Mage::getModel('catalog/product')->load(5);//product id here

foreach ($product->getMediaGalleryImages() as $image) {
                     echo $image->getUrl();
}  

or

<?php foreach ($product->getMediaGalleryImages() as $image) :?>

    <img src="<?php echo Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(100, 100); ?>" alt="<?php echo $product->getName()?>" />

<?php endforeach; ?>