📄 ページテンプレート中級
コレクションページの商品一覧と pagination
コレクション内の商品をグリッド表示し、各商品カードに画像・説明・価格・カートボタンを配置するテンプレート。8件ごとにページネーション分割される。
用途
ストアのコレクションページで、商品一覧をグリッドレイアウトで表示し、訪問者がカートに直接商品を追加できるようにしたいとき。
設置場所
templates/collection.liquid に配置する。Shopify 管理画面でコレクションが開かれると自動的にこのテンプレートが呼び出される。ページネーションは 8 件/ページのため、必要に応じて `by 8` の数字を変更する。
注意点
product_img_url フィルターは古い API で、新しいテーマでは `image_url` フィルターの使用が推奨される。バリアント選択が `display: none` で非表示になっているため、バリアント選択可能な商品の場合は見えないままカートに追加されるリスクがある。比較価格と定価が一致したバリアントでは `price_min != compare_at_price` 判定により比較価格が表示されないので、セール表示ロジックを販売戦略に合わせて確認する。
コード
71 行 / liquid <div id="page" class="innerpage clearfix">
<h1>{{ collection.title }}</h1>
{% if collection.description.size > 0 %}
<div class="latest-news">{{ collection.description }}</div>
{% endif %}
{% paginate collection.products by 8 %}
<ul class="item-list clearfix">
{% for product in collection.products %}
<li>
<form action="/cart/add" method="post">
<div class="item-list-item">
<div class="ili-top clearfix">
<div class="ili-top-content">
<h2><a href="{{product.url}}">{{product.title}}</a></h2>
<p>{{ product.description | truncatewords: 15 }}</p>
</div>
<a href="{{product.url}}" class="ili-top-image"><img src="{{ product.featured_image | product_img_url: 'small' }}" alt="{{ product.title | escape }}"/></a>
</div>
<div class="ili-bottom clearfix">
<p class="hiddenvariants" style="display: none">{% for variant in product.variants %}<span><input type="radio" name="id" value="{{variant.id}}" id="radio_{{variant.id}}" style="vertical-align: middle;" {%if forloop.first%} checked="checked" {%endif%} /><label for="radio_{{variant.id}}">{{ variant.price | money_with_currency }} - {{ variant.title }}</label></span>{% endfor %}</p>
<input type="submit" class="" value="Add to Basket" />
<p>
<a href="{{product.url}}">View Details</a>
<span>
{% if product.compare_at_price %}
{% if product.price_min != product.compare_at_price %}
{{product.compare_at_price | money}} -
{% endif %}
{% endif %}
<strong>
{{product.price_min | money}}
</strong>
</span>
</p>
</div>
</div>
</form>
</li>
{% endfor %}
</ul>
<div class="paginate clearfix">
{{ paginate | default_pagination }}
</div>
<div id="three-reasons" class="clearfix">
<h3>Why Shop With Us?</h3>
<ul>
<li class="two-a">
<h4>24 Hours</h4>
<p>We're always here to help.</p>
</li>
<li class="two-c">
<h4>No Spam</h4>
<p>We'll never share your info.</p>
</li>
<li class="two-d">
<h4>Secure Servers</h4>
<p>Checkout is 256bit encrypted.</p>
</li>
</ul>
</div>
</div>
{% endpaginate %}
出典・ライセンス
- Repository:
- https://github.com/Shopify/liquid
- License:
- MIT
このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。
関連項目
📄 ページテンプレート初級
ページテンプレート
Shopify の汎用ページテンプレート。ページのタイトルと本文コンテンツを Shopify 管理画面から取得して表示する基本的な構造。
📁 liquid·MIT·5 行
📄 ページテンプレート初級
リダイレクト
ヘッドレステーマで Shopify ストアフロントへのリダイレクト機能を提供するセクション。管理画面に「リダイレクト」という名称で登場し、ページから別 URL への誘導を実装する基盤となる。
📁 shopify-headless-theme·MIT·7 行
📄 ページテンプレート初級
トップページの基本テンプレート
Shopify Liquid の最小限のテンプレート例。HTML に日付変数を埋め込み、商品ページへのリンクを配置する基本構造を示す。
📁 liquid·MIT·7 行
📄 ページテンプレート初級
固定ページのテンプレート
Shopify 管理画面で作成した固定ページ(利用規約、プライバシーポリシーなど)を表示するテンプレート。ページタイトルと本文コンテンツを描画する。
📁 mcliquid-theme·MIT·8 行
📄 ページテンプレート初級
ページの基本テンプレート
固定ページ(About など)の基本レイアウト。ページタイトルとコンテンツを HTML の article 要素でマークアップし、管理画面で編集したテキストを表示する。
📁 liquid·MIT·9 行
📄 ページテンプレート初級
固定ページのテンプレート
固定ページ(ポリシー、会社概要、利用規約など)の基本レイアウト。ページタイトルと本文を中央揃えで表示する。
📁 ks-bootshop·MIT·10 行