【问题标题】:Magento filter product gallery images by labelMagento 按标签过滤产品图库图片
【发布时间】:2013-09-11 20:56:47
【问题描述】:

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

在我的目录/产品/视图/media.phtml 文件中,我有以下代码:

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

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

提前致谢!

【问题讨论】:

    标签: php image magento product mage


    【解决方案1】:

    我想出了解决办法。我只需要在显示图像的代码周围添加一个条件。在有条件的情况下,我可以通过调用 $_image->label 来访问标签。像这样:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多