Php Shopify标记所有项目
在Shopify中,如何显示标签列表,然后显示带有该标签的产品数量 示例:黑色(12)、蓝色(10) 目前代码看起来是这样的,但不起作用Php Shopify标记所有项目,php,shopify,Php,Shopify,在Shopify中,如何显示标签列表,然后显示带有该标签的产品数量 示例:黑色(12)、蓝色(10) 目前代码看起来是这样的,但不起作用 <ul> {% for tag in collection.all_tags %} <li> <a href="https://mystore.myshopify.com/collections/all/{{ tag }}"> {{ tag }}
<ul>
{% for tag in collection.all_tags %}
<li>
<a href="https://mystore.myshopify.com/collections/all/{{ tag }}">
{{ tag }}
</a>
({{ tag.products_count }})
</li>
{% endfor %}
</ul>
{%用于集合中的标记。所有_标记%}
-
({tag.products_count}})
{%endfor%}
产品计数
是标签的属性,而不是标签
我相信您需要手动循环浏览产品,并使用指定的标签计算数字
例如:
{% assign collection = collections.all %}
<ul>
{% 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 %}
<li>
<a href="https://mystore.myshopify.com/collections/all/{{ tag }}">
{{ tag }}
</a>
({{ products_count }})
</li>
{% endfor %}
</ul>
{%assign collection=collections.all%}
{%用于集合中的标记。所有_标记%}
{%assign products\u count=0%}
{%用于集合中的产品。产品%}
{%如果product.tags包含标记%}
{%assign products_count=products_count |加:1%}
{%endif%}
{%endfor%}
-
({{products_count}})
{%endfor%}
请参见Shopify论坛上的类似讨论:
产品计数
是标签的属性,而不是标签
我相信您需要手动循环浏览产品,并使用指定的标签计算数字
例如:
{% assign collection = collections.all %}
<ul>
{% 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 %}
<li>
<a href="https://mystore.myshopify.com/collections/all/{{ tag }}">
{{ tag }}
</a>
({{ products_count }})
</li>
{% endfor %}
</ul>
{%assign collection=collections.all%}
{%用于集合中的标记。所有_标记%}
{%assign products\u count=0%}
{%用于集合中的产品。产品%}
{%如果product.tags包含标记%}
{%assign products_count=products_count |加:1%}
{%endif%}
{%endfor%}
-
({{products_count}})
{%endfor%}
请参见Shopify论坛上的类似讨论:
- 斯蒂芬的解决方案正在发挥作用。但是,如果我启用了分组标记并希望显示产品计数。请让我知道以下代码中附加产品计数的解决方案:
'{%comment%} code for color, designer, material sidebar filter {%endcomment%}
{%- for tag in collection.all_tags -%}
{%- assign tag_parts = tag | split: '_' -%}
{%- if tag_parts.size != 2 -%}
{%- continue -%}
{%- endif -%}
{%- assign groups = groups | append: tag_parts.first | append: ',' -%}
{% endfor %}
{%comment%} End of code for color, designer, material sidebar filter {%endcomment%}'
斯蒂芬的解决方案正在发挥作用。但是,如果我启用了分组标记并希望显示产品计数。请让我知道以下代码中附加产品计数的解决方案:
'{%comment%} code for color, designer, material sidebar filter {%endcomment%}
{%- for tag in collection.all_tags -%}
{%- assign tag_parts = tag | split: '_' -%}
{%- if tag_parts.size != 2 -%}
{%- continue -%}
{%- endif -%}
{%- assign groups = groups | append: tag_parts.first | append: ',' -%}
{% endfor %}
{%comment%} End of code for color, designer, material sidebar filter {%endcomment%}'
什么东西在那个代码段中不起作用?({tag.products_count})计数器不起作用“什么东西在那个代码段中不起作用?”({tag.products_count})计数器不起作用“Steph有上面的解决方法。然而,这项功能刚刚在shopify/liquid项目中被请求,希望它能被接受:@BjornForsberg那太好了!斯蒂芬有上述解决办法。然而,这项功能刚刚在shopify/liquid项目中被请求,希望它能被接受:@BjornForsberg那太好了!