You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopify:如何使商品筛选计数匹配带test标签的展示商品数量?

解决Shopify筛选计数与手动产品过滤不匹配的问题

方法一:使用智能集合(推荐)

直接创建一个智能集合,将集合规则设置为「标签包含 test」,之后在模板中调用这个集合而非原集合。这样原生筛选的value.count会自动基于这个智能集合内的产品统计,完全不需要修改筛选计数的代码,性能也最优。

操作步骤:

  • 进入Shopify后台 → 产品 → 集合 → 创建集合
  • 选择「智能集合」,添加条件:标签 → 包含 → test
  • 保存集合后,在模板中把原集合调用改为这个新智能集合的 handle(比如collections.test-products)

方法二:模板内手动统计筛选计数

如果无法创建新集合(比如条件是动态的),可以先预筛选出符合条件的产品,再手动统计每个筛选选项的匹配数量:

  1. 先收集所有带test标签的产品:
{% assign filtered_products = '' | split: '' %}
{% for product in collection.products %}
  {% if product.tags contains 'test' %}
    {% assign filtered_products = filtered_products | push: product %}
  {% endif %}
{% endfor %}
  1. 遍历原筛选选项,统计每个选项在filtered_products中的匹配数:
    以标签筛选为例:
{% for filter in collection.filters %}
  {% for value in filter.values %}
    {% assign match_count = 0 %}
    {% for product in filtered_products %}
      {% if product.tags contains value.handle %}
        {% assign match_count = match_count | plus: 1 %}
      {% endif %}
    {% endfor %}
    {{ value.label }}: {{ match_count }}, 
  {% endfor %}
{% endfor %}

注意事项

  • 模板内遍历统计的方法在产品数量较多时会影响页面加载速度,优先推荐智能集合方案。
  • 如果筛选维度是价格、规格等其他类型,需要对应调整统计逻辑(比如价格区间要判断产品价格是否在区间内)。

内容的提问来源于stack exchange,提问作者s.kuznetsov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 16:35:23