Hi All,
I’ve built a dynamic menu in Shopify theme that automatically detects up to 8 Tags in a Category and pulls them into the Menu. Like so:
{% for collection in collections %} // iterating through all collections
{% if collection.id == 277247852749 and collection.products.size > 0 %} // checking that the collection id matches the one I need
{% for tag in collection.tags %} //iterating through tags in that collection
{% if tag contains 'style' %} //pulling the tags I need for this menu column (e.g. style-SummerWine)
{% increment red-wines-style-count %}
{% if red-wines-style-count < 9 %} // I only need up to 8 menu items in this column to avoid making it huge
{{- tag | remove: 'style ' -}}({{ collection.products_count }})
// this pulls in the tag name and wraps it in a url that points to the category with id 277247852749 and only displays products with that tag applied.
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
Everything above works, except for one: {{ collection.products_count }} does not show the right amount of products.
Say, there is a category (collection) named “Red Wines” and there are 2 products with a Tag “Shiraz” - the {{ collection.products_count }} in the above example will output the amount of products in the whole category.
Is there a way to modify the above code, so it shows only the amount of products with a specific Tag applied to them in the menu?
Thanks!