Magento – Get Magento second image in product view page

magento-1.9product-imagesproduct-view

I want to display image 2 from a product in the product view page next to the description. I need some help putting this code together.

I found some code online, but it gives me image 1 (base image). I need the second image displayed.

Ho can I do this?

Best Answer

Goto admin panel, Catalog >> Manage Products, select your product and goto images section. Use Sort Order column to get the second image.

Please paste the below code in media.phtml file of your theme.

     <?php $i=0; foreach ($this->getGalleryImages() as $_image): ?>
          <?php if($_image['position_default'] == 2): ?>
          <img id="image-<?php echo $i; ?>"
               class="gallery-image"
               src="<?php echo $this->getGalleryImageUrl($_image); ?>"
               data-zoom-image="<?php echo $this->getGalleryImageUrl($_image); ?>" />
          <?php endif;?>
    <?php $i++; endforeach; ?>

Note: Place the image at second order which you want to display at front-end.

Let us know incase of any query/concern.

Related Topic