简体   繁体   English

如何显示代表多个产品的标签? Shopify液体

[英]How do I show a tag to represent multiple products? Shopify Liquid

Hello and thanks for reading my post! 您好,感谢您阅读我的文章!

I have a collection with multiple products. 我有多个产品的集合。 On a custom collection template, I want to show the tags only for those that contain multiple products (or when more than 1 product in that collection have the same tag) 在自定义集合模板上,我只想显示包含多个产品的标记(或当该集合中的多个产品具有相同标记时)

I assume it would go something like: 我认为它会像这样:

  {% for tag in collection.all_tags %}
    {% if tag.product.size >= 1 %}
      has more than 1 product.  
    {% endif %}
  {% endfor %}

I've answered similar questions here and here . 我在这里这里都回答过类似的问题。

You want something like this: 您想要这样的东西:

{% for tag in collection.all_tags %}
    {% assign products_count = 0 %}
    {% for product in collection.products %}
        {% if product.tags contains tag %}
            {% assign products_count = products_count | plus: 1 %}
        {% endif %}
    {% endfor %}

    {% if products_count > 1 %}
        {{ tag }}
    {% endif %}
{% endfor %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Shopify Liquid-如果product.template包含 - Shopify Liquid - if product.template contains 如何不打印嵌套循环中不需要的产品? - How do I not print the unwanted products of a nested loop? SQL:如何基于相似值标记行? - SQL: How do I tag rows based on like values? 在prolog中,您如何表示状态转换和对象执行的操作? - In prolog how do you represent state transitions and actions performed by objects? 我将如何在谓词逻辑中表示以下prolog语句? - How would I represent the following prolog statement in predicate logic? 如何将自枚举pangram表示为布尔函数? - How can I represent a self-enumerating pangram as a boolean function? 如何在序言中表示OR功能 - how to represent OR function in prolog 如何在反应中有条件地显示文本字段? - How do I conditionally show text field in react? 如何在基于树的 g.netic 编程中表示多输出逻辑电路 - How to represent multiple-output logic circuits in tree-based genetic programming 如何在 cfif 语句中放置多个 NOT 条件? - How do I place multiple NOT conditions inside of a cfif statement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM