Topページにバリエーション(オプション)毎に商品を表示したい

Topic summary

Shopify初心者が、TOPページでバリエーション(オプション)ごとに商品を表示し、商品タイトルを「商品名 バリエーション名」(例:Tシャツ 赤)の形式にする方法を質問。

解決プロセス:

  • 最初の回答で基本的なLiquidコードが提示されたが、質問者は特定のコレクションに属する商品のバリエーションを表示したいと追加要望
  • collections['コレクション名']を使用したコードで何も表示されない問題が発生
  • additions.productsを使用する必要があることが判明し、修正されたコードで解決

最終的なコード構造:

{% assign additions = collections['terminal'] %}
{% for product in additions.products %}
  {% for variant in product.variants %}
    {{ product.title }} {{ variant.title }}
    {{ variant.compare_at_price }}
  {% endfor %}
{% endfor %}

新たな質問:
別のユーザーが関連質問として、複数のオプション(カラー、サイズなど)がある場合に、特定のオプション(カラーのみ)を表示させる方法について質問中。現在未解決。

Summarized with AI on November 16. AI used: claude-sonnet-4-5-20250929.

shopify初心者です。

TOPページにバリエーション(オプション)毎に商品を表示したいのですが、

うまくいきません。

またその際、商品タイトルは「商品名 バリエーション名」としたいです。

例:Tシャツ 赤

初歩的な質問で申し訳ございませんが、

よろしくお願いします。

<ul>
{% for variant in product.variants %}
<li>
<img src="{{ variant.image | img_url }}">
<p>{{ variant.title }}</p>
<p>{{ variant.compare_at_price | money }}</p>
</li>
{% endfor %}
</ul>

{% for variant in product.variants %}
- {{product.title | append:" - " | append:variant.title}}

  {{ variant.compare_at_price | money }}

{% endfor %}

細かいですが補足です。

Simonsronさんの回答でOKですが、

またその際、商品タイトルは「商品名 バリエーション名」としたいです。> > 例:Tシャツ 赤

ということなので、appendする文字列を部分を少し修正して


{% for variant in product.variants %}
- {{ product.title | append: " " | append: variant.title }}

  {{ variant.compare_at_price | money }}

{% endfor %}

とすると意図通りに表示されると思います。

Simonsron様

KyoheiOgasawara様

ご返信ありがとうございます!

質問が五月雨になってしまい申し訳ございません。

「あるコレクションに属する商品のバリエーション」を出力したいため、

いただいた内容に変数を導入したのですが、何も表示されず。。。

{% assign addition = collections['コレクション名'] %}

{% for variant in addition.variants %}
- {{ product.title | append: " " | append: variant.title }}

  {{ variant.compare_at_price | money }}

{% endfor %}

出力方法を教えていただけますでしょうか?

よろしくお願いいたします。

{% assign addition = collections['コレクション名'] %}

{% for product in addition %}
{% for variant in product.variants %}
variant.......
{% endfor %}
{% endfor %}

Simonsron様

ありがとうございます。

いただいたタグを追記したのですが、表示されず。。。

下記実際のコードです。

{% assign additions = collections['terminal'] %}

{% for product in additions %}
{% for variant in product.variants %}
- {{ product.title | append: " " | append: variant.title }}

  {{ variant.compare_at_price | money }}

{% endfor %}
{% endfor %}

{% assign additions = collections['terminal'] %}

{% for product in additions.products %}
{% for variant in product.variants %}
- {{ product.title | append: " " | append: variant.title }}

  {{ variant.compare_at_price | money }}

{% endfor %}
{% endfor %}

Oh! Sorry!

Try this!

1 Like

Dear Mr. Simonsron

It’s done!
Thank you so much!

関連した質問をしたく、恐縮ですがこちらから失礼致します。

こちらの例のようにバリエーション(オプション)毎に商品を表示したいのですが、

私の場合、「カラー」のバリエーションのみを表示させたいです。

サイズなど他のオプションについては、無視したいのですが、どのように記述すればよろしいでしょうか。

商品:Tシャツ

カラー 赤,青

サイズ S,M,L

という商品がある場合には、Tシャツの赤とTシャツの青2種類を並べるイメージです。