简体   繁体   中英

Magento filter product gallery images by label

I have some product images that should not be displayed in the main product image gallery in magento. I have given a specific label to the images that should not be displayed in the gallery but I am unsure of how to filter the images based on the label.

In my catalog/product/view/media.phtml file I have the following code:

<?php foreach ($this->getGalleryImages() as $_image): ?>
  <?php // code to display the images ?>
<?php endforeach; ?>

I would like to filter the array of images returned from the getGalleryImages() call before looping over them in the template. Is there are easy way to get the label of each of the images and then filter based on the value of the label?

Thanks in advance!

I figured out the solution to this. I just need to add a conditional around the code that displays the image. In the conditional I can access the label by calling $_image->label. Like so:

<?php foreach ($this->getGalleryImages() as $_image): ?>
    <?php if ($_image->label == 'somelabel'):
        <?php // code to display the images ?>
    <?php endif; ?>
<?php endforeach; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM