Liquid Snippets by ALSEL
🔍 コレクション/検索中級

カテゴリ階層の複数列グリッド表示

コレクション配下のカテゴリ一覧を複数列グリッドで表示するセクション。ブロック単位でカテゴリ画像、タイトル、説明、子カテゴリリンクを管理し、ホバー時に画像プリロードして遷移を高速化する。

用途
トップページやカテゴリランディングページで、親カテゴリ配下の子カテゴリを視覚的に一覧表示したいとき。メタオブジェクトで階層構造を管理して、次階層へのプリロードで UX を改善できる。
設置場所
sections/category-multicolumn.liquid に配置し、テーマカスタマイザーでセクションを追加して「Collection」を選択、各ブロックでカテゴリ画像・タイトル・説明・次階層の子カテゴリメタオブジェクト・リンク URL を設定する。
注意点
next_children メタオブジェクトが正しく登録されていることが前提。ブロック内のリンク URL がハードコードされているため、カテゴリ構造を変更するたびに管理画面で手動更新が必要になる。タイトルを 『 > 』 で分割して末尾を抽出しているため、カテゴリ名に 『 > 』 が含まれる場合は正しく表示されない。
タグ:collectionmetaobjectgrid-layoutcategoryimage-preload

コード

112 行 / liquid
{% stylesheet %}
  .card {
    display: flex;
    font-size: 0.8rem;
    gap: 0.5rem;
    border: 1px solid lightgrey;
    padding: 0.5rem;
    border-radius: 0.25rem;
    text-decoration: none;
    color: black;
  }
  .card:hover {
    background-color: lightgrey;
  }
  .card:hover .card__title {
    text-decoration: underline;
  }
  .card__image {
  }
  .card__content {
    flex: 2;
  }
  .card__title {
    font-size: 0.8rem;
  }
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(25rem, 1fr));
    gap: 0.5rem;
    margin: 0.5rem;
  }
{% endstylesheet %}

{% if section.blocks.size > 0 %}
  <h1 class="sticky-header">
    All Categories >
    {{ section.settings.collection.title }} ({{ section.blocks.size }}
    {{ section.blocks.size | pluralize: 'category', 'categories' }})
  </h1>
{% endif %}

{% if section.blocks.size > 0 %}
  <div class="grid">
    {%- for block in section.blocks -%}
      {% for child in block.settings.next_children %}
        <link rel="preload" as="image" href="{{ child.image | image_url: width: 150 }}">
      {% endfor %}
      <a href="{{ block.settings.link }}" class="card prefetch">
        <div class="card__image">
          {{ block.settings.image | image_url: width: 150 | image_tag: alt: block.settings.title }}
        </div>
        <div class="card__content">
          <div class="card__title">{{ block.settings.title | split: ' > ' | last }}</div>
          <div class="card__description">{{ block.settings.description }}</div>
        </div>
      </a>
    {%- endfor -%}
  </div>
{% endif %}

{% schema %}
{
  "name": "Category Multicolumn",
  "class": "section",
  "tag": "section",
  "disabled_on": {
    "groups": ["header", "footer"]
  },
  "settings": [
    {
      "type": "collection",
      "id": "collection",
      "label": "Collection"
    }
  ],
  "blocks": [
    {
      "type": "column",
      "name": "Column",
      "settings": [
        {
          "type": "image_picker",
          "id": "image",
          "label": "t:sections.multicolumn.blocks.column.settings.image.label"
        },
        {
          "type": "inline_richtext",
          "id": "title",
          "label": "t:sections.multicolumn.blocks.column.settings.title.label"
        },
        {
          "type": "richtext",
          "id": "description",
          "label": "description text"
        },
        {
          "type": "metaobject_list",
          "id": "next_children",
          "metaobject_type": "category_metaobject",
          "label": "next children"
        },
        {
          "type": "url",
          "id": "link",
          "label": "link url"
        }
      ]
    }
  ]
}
{% endschema %}

出典・ライセンス

License:
MIT

このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。

関連項目

🔍 コレクション/検索初級

ページネーションの表示

ページネーションUI(前へ・次へ、ページ番号)を paginate オブジェクトから描画するスニペット。デフォルトのページネーション形式で複数ページに分割したコンテンツをナビゲートできる。

📁 shopify-code-snippets·MIT·6
🔍 コレクション/検索初級

ページネーションの現在位置表示

コレクションや検索結果の一覧ページで、現在のページ番号と全ページ数を表示する。Shopify の多言語対応翻訳キーを使用して、言語ごとに自動で表記を切り替える。

📁 shopify-code-snippets·MIT·6
🔍 コレクション/検索中級

検索結果のペジネーション比較

検索結果を paginate タグで複数パターン分割して表示するテンプレート。デフォルトペジネーションと window_size:1 オプション指定の両方の書き方を示しており、ページネーション動作の違いを検証するサンプルコード。

📁 theme-tools·MIT·12
🔍 コレクション/検索初級

検索結果のページネーション設定

検索結果を paginate タグでページ分割し、複数の window_size 設定を並べて出力する方法。28件単位のペーグネーションと、ウィンドウサイズを明示的に指定した設定の2パターンを示している。

📁 theme-tools·MIT·12
🔍 コレクション/検索初級

コレクションページの商品ギャラリー

コレクション内の商品を3列のテーブルレイアウトで表示するテンプレート。各商品にサムネイル、タイトル、価格(セール時は定価を取消線)を表示し、ページネーションに対応する。

📁 liquid·MIT·20
🔍 コレクション/検索初級

コレクションページの商品一覧

コレクション内の商品を一覧表示し、商品画像・タイトル・説明文・価格帯をカード状に並べる。ページネーション機能で20件ごとに分割表示する。

📁 liquid·MIT·23