How to display single product tag name in Shopify?

做~自己de王妃 提交于 2019-12-11 15:50:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!