当前标记在Shopify中显示多个标记名称 [英] Current tag displaying more than one tag name in Shopify

查看:120
本文介绍了当前标记在Shopify中显示多个标记名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示产品标签。如果用户点击所有产品过滤器,那么它将仅显示第一个单个标签。如果用户点击任何当前标记,则它将显示在当前标记名称上。

I am displaying the product tags. If the user clicked on All products filter then It will display only first single tag. If the user clicks on any current tag then it will display on the current tag name.

  {% for tag in product.tags %}
     {% if current_tags contains tag %}
     <a class="link" href="/collections/{{ collection.handle }}">{{ tag | link_to_tag: tag }}</a>

   {% else %}
   <a class="link" href="/collections/{{ collection.handle }}">{{ product.tags[0] | link_to_tag: tag }}</a>
     {% endif %}
   {% endfor %}

以上代码是显示所有标签

Above code is displaying all the tag

我的逻辑是

for(display all tag){
if(clicked current tag){
   display current tag name which is clicked
}
else{
display first tag name
}
}


推荐答案

您可以通过以下方式实现:

You can achieve it with the following:

{% assign product_tags = products | map: 'tags' %}
     {% if product_tags contains current_tags %}
     <a class="link" href="/collections/{{ collection.handle }}">{{ current_tags | link_to_tag: current_tags }}</a>

   {% else %}
    {% assign first_tag = product.tags | first %}
   <a class="link" href="/collections/{{ collection.handle }}">{{ first_tag | link_to_tag: first_tag }}</a>
     {% endif %}

尝试在您所需的位置更新此代码并告诉我你是否得到了结果。

Try updating this code in your required place and let me know whether you got the result.

这篇关于当前标记在Shopify中显示多个标记名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆