Magento display multiple product images on details page

Magento display multiple product images on details page

July 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento display multiple product images on details page

Displaying Multiple Product Images on Magento Product Details Page

Magento provides robust functionality for managing product images, including multiple images per product. In this post, we’ll walk through how to display both the primary product image and additional secondary images on the product details page.

Understanding Magento Product Image Structure

In Magento, each product can have a base image (primary image) and an unlimited number of gallery images. These images are stored in the media directory in your Magento installation, under the relevant category-product-image folder structure.

Displaying the Primary Product Image

To display the primary product image on the details page, you’re already using the correct approach with the catalog/image helper:

$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(180, 300).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');

This code initializes the catalog/image helper with the current product and image type (‘image’), then resizes it to 180x300 pixels before echoing it as a product attribute.

Retrieving Additional Product Images

You’re on the right track for retrieving additional images. The media_gallery array can be accessed using $_product->getData()['media_gallery']['images']. However, this returns an array of image data:

$productImages = $_product->getMediaGalleryImages();

Each element in the $productImages array is astdObject with properties like file, label, position, etc. You can loop through these images to display them separately.

Displaying Additional Images Separately

To display each secondary image on its own, you can use the same catalog/image helper approach within a foreach loop:

<?php if (count($productImages) > 0): ?>
    <div class="additional-images">
        <?php foreach ($productImages as $_image): ?>
            <a href="#" data-image-popup="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image['file'])->keepFrame(false)->resize(180, 300); ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image['file'])->keepFrame(false)->resize(50, 50); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel()); ?>"/>
            </a>
        <?php endforeach; ?>
    </div>
<?php endif; ?>

This code loops through each image in the $productImages array. It initializes a new catalog/image helper for each image with the product, ‘image’ type, and the specific file name of the current image.

The data-image-popup attribute is used to link the image to a lightbox or popup extension like Fancybox or Magnific Popup for better user experience.

Conclusion

In this post, we explored how to display both primary and secondary product images on the Magento product details page using the catalog/image helper. By retrieving the additional gallery images and looping through them, you can create a clean, separate display for each image without needing to hardcode any URLs or use external JavaScript libraries.

Remember to use the catalog/image helper consistently across your theme template files for consistency and better performance.

For more advanced product image customization and management, check out our guide on Working with Product Images in Magento.

Happy coding!

Catalog

Our network