0

I'm trying to pull through the gallery images on the product page because customizing the gallery with code:

<?php $_product = $block->getProduct(); ?>
<?php $gallery = $_product->getMediaGalleryImages(); ?>

<?php foreach ($gallery as $galleries): ?>
  <figure><?php echo $galleries ?></figure>
<?php endforeach; ?>

But first image is not loading. How fix this?

2 Answers 2

0

Try below code to get Array of gallery images in gallery.phtml file

$loop=json_decode($block->getGalleryImagesJson());
0

You can try in this way (with objectmanager)

<?php
    $_product = $block->getProduct();
    $objectmanager = \Magento\Framework\App\ObjectManager::getInstance();
    $product_id = $_product->getId();
    $productimages = array();
    $product = $objectmanager->create('Magento\Catalog\Model\Product')->load($product_id);
    $productimages = $product->getMediaGalleryImages();
    foreach ($productimages as $productimage) {

        echo "<img src=" . $productimage['url'] . " alt=" . $_product->getName() . ">";

    }
    ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.