按多个过滤器对Shopify产品进行排序

时间:2015-02-12 17:05:38

标签: sorting shopify

我正在尝试按多个过滤器对产品集合进行排序。我想按照标记(collection.products | sort: 'tags')和标题升序(collection.products | sort: 'title')对产品进行排序。我尝试了以下多种变体:

{% assign sortedProducts = collection.products | sort: 'title' | sort: 'tags' %}
{% assign sortedProducts = collection.products | sort: 'tags' | sort: 'title' %}
{% assign sortedProducts = collection.products | sort: 'title' %}
{% assign sortedProducts = sortedProducts | sort: 'tags' %}
{% assign sortedProducts = collection.products | sort: 'tags' %}
{% assign sortedProducts = sortedProducts | sort: 'title' %}

它们都不起作用。我已经看到问题的答案涉及按标签过滤然后按字母顺序排序,但我希望在同一页面上按标签和标题排序。如果不可能,那么在排序之前,我会更多地按标签过滤。

谢谢!

1 个答案:

答案 0 :(得分:0)

显然,对于液体标签,您不应该留下空间,如下图所示(未经测试):

{% assign sortedProducts = collection.products|sort:'title'|sort:'tags' %}
{% assign sortedProducts = collection.products|sort:'tags'|sort:'title' %}
{% assign sortedProducts = collection.products|sort:'title' %}
{% assign sortedProducts = sortedProducts|sort:'tags' %}
{% assign sortedProducts = collection.products|sort:'tags' %}
{% assign sortedProducts = sortedProducts|sort:'title' %}

然后还有一个复杂因素:分页。 在您的设置或主题设置中的某处设置了分页设置。默认设置为每页' 50个产品。我的经验中的问题是当你要求它排序时它可能只在前50种产品中排序:(