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

如何编写Shopify Collection循环:仅展示产品数超10的集合并加链接

Shopify Liquid 集合循环实现方案

这就给你写出完全符合需求的Liquid代码,同时拆解每一部分的作用,方便你理解和调整:

{% comment %} 遍历店铺内所有集合 {% endcomment %}
{% for collection in collections %}
  {% comment %} 过滤出产品数量大于10的集合 {% endcomment %}
  {% if collection.products.size > 10 %}
    <div class="collection-item">
      {% comment %} 将集合标题链接到对应集合页面 {% endcomment %}
      <a href="{{ collection.url }}">{{ collection.title }}</a>
    </div>
  {% endif %}
{% endfor %}

代码细节说明:

  • {% for collection in collections %}:循环遍历你的Shopify店铺中所有已创建的产品集合
  • {% if collection.products.size > 10 %}:通过判断集合内的产品数量,只保留产品数超过10个的集合;如果需要包含刚好10个产品的集合,把>改成>=即可
  • <a href="{{ collection.url }}">{{ collection.title }}</a>:把集合标题渲染成可点击的链接,点击后直接跳转到该集合的官方页面

你可以根据自己的页面设计需求,调整外层的div标签、添加CSS类或者额外的样式代码来优化显示效果。

内容的提问来源于stack exchange,提问作者user5827348

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:22:58