If statement 在Shopify中显示多个标签名的当前标签

If statement 在Shopify中显示多个标签名的当前标签,if-statement,tags,shopify,product,If Statement,Tags,Shopify,Product,我正在显示产品标签。如果用户单击所有产品过滤器,则只会显示第一个标签。如果用户单击任何当前标记,则它将显示在当前标记名称上 {% for tag in product.tags %} {% if current_tags contains tag %} <a class="link" href="/collections/{{ collection.handle }}">{{ tag | link_to_tag: tag }}</a> {%

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

  {% 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 %}

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

{% 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 %}
{%assign product_tags=products|map:'tags'%}
{%如果产品_标记包含当前_标记%}
{%else%}
{%assign first_tag=product.tags | first%}
{%endif%}

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

是,否则部分无法工作。我的意思是它显示了所有的标签。我只需要一个标签或第一个标签当前标签液体错误(产品卡网格线6)存在一些问题:标签过滤器参数必须是字符串或标签,否则部分工作正常,但当我单击标签时,当前标签未显示getting error我只有三个标签,分别是apple、mango、banana。因此,我点击了苹果,我得到了一个错误,给我10分钟,我会与你分享你必须点击收集的图片,你会在产品图片的顶部得到两个产品,你会得到第一个标签名,这是正确的。现在点击过滤器部分的kivi_标签,你们会得到两个产品,但这次标签名是kivi_2_标签和kivi_1_标签。我需要kivi_标记图像
{% 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 %}