[英]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.