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

**URL:** <https://community.shopify.com/t/topic/11231>\
**Category:** 技術的なQ＆A\
**Created:** [April 17, 2020, 9:41am UTC](https://community.shopify.com/t/topic/11231 "2020-04-17T09:41:41Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

コレクションページ内でも、現在表示中のコレクション以外のコレクションを取得できるかが焦点。目的は、春物・夏物のように分けた複数コレクションの商品を、別のページや構成内でまとめて表示すること。 

途中では、LiquidオブジェクトはShopify APIに近い階層構造を持つため、`collection.products` で取得した `product` から関連コレクションをたどる方法が候補として挙げられた。`Liquid` はShopifyテーマ用テンプレート言語。 

最終的には、グローバルな `collections` オブジェクトを使う方法で解決している。具体的には `{{ collections.COLLECTION_NAME.title }}` や `{% for product in collections.COLLECTION_NAME.products %}` で、指定ハンドルの別コレクション情報や商品一覧を取得できることが確認された。 

結論として、質問は解決済み。現在のコレクション経由で回り込む必要はなく、別コレクションを直接参照する方法が有効とされた。

<div class="post-metadata">

**Author:** ![kenta](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@kenta](https://community.shopify.com/u/kenta)\
**Post date:** [April 17, 2020, 9:41am UTC](https://community.shopify.com/t/topic/11231/1 "2020-04-17T09:41:41Z")

</div>

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

コレクションページでは  
collections/collection-A  
{% for product in collection.products %}  
このループでコレクションが取れるかと思いますが、

このページで他のコレクション  
collection-B  
を取得することは可能でしょうか？

春物、夏物などでコレクションを分け、トップページでは春物も夏物も表示させたいと考えています

---

<div class="post-metadata">

**Author:** ![junichiokamura](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/junichiokamura/32/299737_2.png) [@junichiokamura](https://community.shopify.com/u/junichiokamura)\
**Post date:** [April 20, 2020, 3:04pm UTC](https://community.shopify.com/t/topic/11231/2 "2020-04-20T15:04:38Z")

</div>

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

[https://shopify.dev/docs/storefront-api/reference/object/collection#types-that-return-collection-2020-04](https://shopify.dev/docs/storefront-api/reference/object/collection#types-that-return-collection-2020-04)

[https://shopify.dev/docs/themes/liquid/reference/objects/product#product-collections](https://shopify.dev/docs/themes/liquid/reference/objects/product#product-collections)

検証してないですが、

{% for product in collection.products %}

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

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

---

<div class="post-metadata">

**Author:** ![kenta](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@kenta](https://community.shopify.com/u/kenta)\
**Post date:** [May 18, 2020, 5:50am UTC](https://community.shopify.com/t/topic/11231/3 "2020-05-18T05:50:09Z")

</div>

こちらで取得できました

{{ collections.COLLECTION\_NAME.title }}  
{% for product in collections.COLLECTION\_NAME.products %}  
//コレクションのアイテムを表示する記述  
{% endfor %}
