我有一些产品图片不应该显示在洋红色的主产品图片库中。我已经为不应显示在图库中的图像提供了特定的标签,但我不确定如何根据标签过滤图像。
在我的目录/产品/视图/媒体.phtml文件中,我有以下代码:
<?php foreach ($this->getGalleryImages() as $_image): ?>
<?php // code to display the images ?>
<?php endforeach; ?>
我想过滤从 getGalleryImages() 调用返回的图像数组,然后再在模板中循环访问它们。有没有简单的方法可以获取每个图像的标签,然后根据标签的值进行过滤?
提前感谢!
我想出了解决这个问题的方法。我只需要在显示图像的代码周围添加一个条件。在条件中,我可以通过调用 $_image->label 来访问标签。这样:
<?php foreach ($this->getGalleryImages() as $_image): ?>
<?php if ($_image->label == 'somelabel'):
<?php // code to display the images ?>
<?php endif; ?>
<?php endforeach; ?>