Shopify counts per tags

前端 未结 1 1941
Happy的楠姐
Happy的楠姐 2021-01-23 14:17

I am new to shopfiy.I have affffded tags like Black, Blue, Green etc. Now i want to show count like

Black(12)

Blue(1)

Green(4)

1条回答
  •  滥情空心
    2021-01-23 15:07

    My answer to a similar question might help you with this: Shopify Tags total items

    To get a count of all the products with a given tag you need to loop over the products and manually count them.

    For example:

    {% assign collection = collections.all %}
    
    {% 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 %}
    
        

    {{ tag }} ({{ products_count }})

    {% endfor %}

    0 讨论(0)
提交回复
热议问题