问题
I have more than 20 products and each product have 2-3 tags. I am displaying all the product tags using this code
{% 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 %}
<a class="filter__link" href="/collections/{% if collection.handle != blank %}{{ collection.handle }}{% else %}all{% endif %}/{{ tag | handleize }}"{% if current_tags contains tag %} selected="selected" id="tag_active"{% endif %}>{{ tag }} ({{products_count }})</a>
{% endfor %}
And output I am getting it
Apple(3)
mango(2)
banana(3)
Now I have to show the one tag name over the image. I am not getting it. If I clicked on any tag name (which I am getting in above output) then I am getitng the one tag name over image using below code.
{% for tag in product.tags %}
{% if current_tags contains tag %}
<a class="link" href="/collections/{{ collection.handle }}">{{ tag | link_to_tag: tag }}</a>
{% endif %}
{% endfor %}
Would you help me out in this?
I need an output like this but I am getting blank tag over image
This output I am getting to click on Apple which is correct.
来源:https://stackoverflow.com/questions/49669197/how-to-display-single-product-tag-name-in-shopify