【问题标题】:Shopify - how to select all products in a specific collection?Shopify - 如何选择特定系列中的所有产品?
【发布时间】:2013-10-28 15:53:20
【问题描述】:

我是 Shopify 的新手,我正在尝试获取我添加到我制作并称为“我的目录”的集合中的所有产品图片。

我已经从这个开始了,它正在循环遍历所有图像,但是如何只选择具有“mycatalog”集合的图像?

{% for product in collection.products %}

<div>
    <a href="{{ url }}">
      <div style="background-image: url('{{ product.featured_image | product_img_url: 'large' }}');"> </div>
</a>
</div>

  {% endfor %}

我已经测试了一些不同的东西,但我无法让它工作!

一个例子将有助于理解它是如何工作的。 任何意见表示感谢。

【问题讨论】:

    标签: shopify


    【解决方案1】:

    试试这个:

    {% for product in collections.mycatalog.products %}
    
    <div>
      <a href="{{ url }}">
        <div style="background-image: url('{{ product.featured_image | product_img_url: 'large' }}');"> </div>
      </a>
    </div>
    
    {% endfor %}
    

    有关更多信息,请参阅 Shopify wiki 上的 Global variables 页面:

    {% for product in collections.frontpage.products %}
       {{ product.title }} 
    {% endfor %}
    

    液体变量“collections”包含所有 商店里的收藏品。

    【讨论】:

    • 不确定这是否是 Shopify 的新更新,但值得注意的是,目前此代码不起作用。在此示例中,集合名为 My Catalog,并且在代码中输入为 mycatalog - 它不输出任何内容。在代码中,如果您将其更改为 my-catalog 它然后输出。认为对于像我这样的人在发布几年后找到此解决方案的记录会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 2019-12-25
    • 2020-09-28
    相关资源
    最近更新 更多