Question

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.

Was it helpful?

Solution

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; ?>

OTHER TIPS

<?php 
    $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
 ?>
<?php 
   if($_images){?>          
  <?php  $i=0; foreach($_images as $_image){ $i++;?>
  <a href="#">
    <img src="<?=$this->helper('catalog/image')->init($_product, 'image', $_image->getFile()); ?>"alt="<?=$this->htmlEscape($_image->getLabel());?>" title="<?=$this->htmlEscape($_image->getLabel());?>" />
   </a>             
<?php  } ?>
<?php  } ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top