Magento按标签过滤产品图库图像

时间:2013-09-10 20:43:12

标签: php image magento product mage

我有一些产品图片不应该显示在magento的主产品图库中。我已经为不应在图库中显示的图像指定了特定标签,但我不确定如何根据标签过滤图像。

在我的catalog / product / view / media.phtml文件中,我有以下代码:

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

我希望过滤从getGalleryImages()调用返回的图像数组,然后在模板中循环它们。是否有简单的方法来获取每个图像的标签,然后根据标签的值进行过滤?

提前致谢!

1 个答案:

答案 0 :(得分:0)

我找到了解决方法。我只需要在显示图像的代码周围添加一个条件。在条件中,我可以通过调用$ _image-&gt;标签来访问标签。像这样:

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