【问题标题】:Display product loop based on tag only in Shopify仅在 Shopify 中基于标签显示产品循环
【发布时间】:2021-12-01 01:15:46
【问题描述】:

我正在尝试在 Shopify 上的 Collection 模板中显示产品循环。我想提取所有带有特定标签“水合物”的产品以显示在集合中。

模板文件是 collection.custom.liquid,到目前为止我有以下内容:

{% for product in collection.products %}   
{% if product.tags contains "Hydrate" %} 
 Do Something
{% endif %}
{% endfor %}

但它不显示任何内容。我已经确认我确实正确设置了标签,并且我什至使用完全相同的大小写敏感度以防万一。

如果有人能指出正确的方向,在自定义集合模板中显示标签“Hydrate”中的产品,那就太好了!非常感谢

编辑

我现在更改了代码并将其移到任何分页之外,并为每个产品添加到下面。它现在显示,但是它在页面上继续显示相同的标签 5 次。我的语法有问题吗?有什么想法吗?

{% for product in collection.products %} 
  {% for product in products %}
    {% if product.tags contains "Hydrate" %} 
        <p>{{ product.title }}</p>
    {% endif %}
  {% endfor %}
{% endfor %}
      

编辑 2

如果其他人将来遇到同样的问题,下面的代码最终会起作用并显示正确的标签,正确的次数:

{% assign products = collection.products %}
  {% for product in products %}
    {% if product.tags contains "Hydrate" %} 
        <p>{{ product.title }}</p>
  {% endif %}
{% endfor %}

【问题讨论】:

  • 我认为您需要在后端创建特定的集合并使用标签将产品过滤到后端,并将它们显示到页面中

标签: shopify liquid


【解决方案1】:

您的代码是正确的,因此可能是分页问题。例如,第一页没有带有此标签的产品,但第二页有。

【讨论】:

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