Google+

Pages

Sunday, April 1, 2012

Getting all images of every product in Magento

To get all gallary images of a product, try this code:

<?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, 'thumbnail',$_image->getFile())->resize(200, 130); ?>" width="200" height="130" alt="<?=$this->htmlEscape($_image->getLabel());?>" title="<?=$this->htmlEscape($_image->getLabel()); ?>" />
      </a>
   <?php  } ?>
<?php  } ?>



Note: Here $_product denotes product, that we got from "catalog/product" collection.

No comments: