FROM CACHE - jp_header
解決済

コレクションページ内での別コレクションの取得について

kenta
Shopify Partner
9 1 1

コレクションページ内で別コレクションの取得について

 
コレクションページでは
collections/collection-A
{% for product in collection.products %}
このループでコレクションが取れるかと思いますが、
 
このページで他のコレクション
collection-B
を取得することは可能でしょうか?
 
春物、夏物などでコレクションを分け、トップページでは春物も夏物も表示させたいと考えています
1 件の受理された解決策

kenta
Shopify Partner
9 1 1

成功

こちらで取得できました
 
{{ collections.COLLECTION_NAME.title }}
{% for product in collections.COLLECTION_NAME.products %}
//コレクションのアイテムを表示する記述
{% endfor %}
 

元の投稿で解決策を見る

2件の返信2

junichiokamura
Community Manager
1200 280 506

liquidのオブジェクトはAPIと同じ階層構造になっているので、コレクションの親のデータ(collectionの場合product)がある場所であれば参照できると思います。

https://shopify.dev/docs/storefront-api/reference/object/collection#types-that-return-collection-202...

https://shopify.dev/docs/themes/liquid/reference/objects/product#product-collections

検証してないですが、

{% for product in collection.products %}

で引いたproductからcollections をまたループして、今のコレクション以外を取得するなどになるかと思います。

(鶏卵みたいな参照になりそうですが。。)

Senior Partner Solutions Engineer

kenta
Shopify Partner
9 1 1

成功

こちらで取得できました
 
{{ collections.COLLECTION_NAME.title }}
{% for product in collections.COLLECTION_NAME.products %}
//コレクションのアイテムを表示する記述
{% endfor %}