获取当前 Shopify collection 中所有产品的 collection 列表
Get a list of collections for all products in current Shopify collection
对于服装的产品类型,我们有一个 collection t-shirts 的主要 collection(产品类型只是为了以防万一,所以没有人会提出来)。
而且它们都在其他一些 collection 中,例如 "linen t-shirts"、"silk t-shirts" 等。
假设我在 t-shirts collection 的页面上,我需要显示所有次要 collection 的列表,如亚麻、丝绸等。我怎么做?
到目前为止,我可以使用以下代码获得每个产品的 collection 列表。此外,我会拉他们并用 js 排序。但我真的希望有一种更简单的方法来获取列表。
这是我为每个产品的 collection 列表使用的液体代码:
{% for product in collection.products %}
{% for collection in product.collections %}
<div>{{collection.title}}</div>
{% endfor %}
{% endfor %}
p.s。
变体也不是一个选项
在 collection 页面上,获取所有 collection。如果您当前的 collection 句柄是 t-shirt 而您的子 collection 句柄是 linen-t-shirt。检查所有包含当前 collection 句柄的 collection,然后显示详细信息。
{% assign currentCol = collection.handle %}
{% for collection in collections %}
{% if collection.handle contains currentCol %}
{{ collection.title }}
// further code
{% endif %}
{% endfor %}
对于服装的产品类型,我们有一个 collection t-shirts 的主要 collection(产品类型只是为了以防万一,所以没有人会提出来)。 而且它们都在其他一些 collection 中,例如 "linen t-shirts"、"silk t-shirts" 等。 假设我在 t-shirts collection 的页面上,我需要显示所有次要 collection 的列表,如亚麻、丝绸等。我怎么做? 到目前为止,我可以使用以下代码获得每个产品的 collection 列表。此外,我会拉他们并用 js 排序。但我真的希望有一种更简单的方法来获取列表。
这是我为每个产品的 collection 列表使用的液体代码:
{% for product in collection.products %}
{% for collection in product.collections %}
<div>{{collection.title}}</div>
{% endfor %}
{% endfor %}
p.s。 变体也不是一个选项
在 collection 页面上,获取所有 collection。如果您当前的 collection 句柄是 t-shirt 而您的子 collection 句柄是 linen-t-shirt。检查所有包含当前 collection 句柄的 collection,然后显示详细信息。
{% assign currentCol = collection.handle %}
{% for collection in collections %}
{% if collection.handle contains currentCol %}
{{ collection.title }}
// further code
{% endif %}
{% endfor %}