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

コレクションページのフィルター・ソート操作パネル

コレクションページ上部に商品数表示、フィルターボタン、ソートドロップダウンを配置するユーティリティコンポーネント。アクティブなフィルター数をボタンに表示し、Bootstrap のオフキャンバス・ドロップダウンで UI を構成する。

用途
コレクションテンプレートで、ユーザーが商品を絞り込み・並び替えするための操作パネルが必要なとき。フィルター数の表示で、すでに条件が適用されていることを視覚的に伝える。
設置場所
snippets/collection-utilities.liquid に配置し、collection テンプレートまたは collection セクションの商品リスト上部で `{% render 'collection-utilities' %}` で呼び出す。section.settings の `show_product_count`、`show_filters`、`show_sort_by`、`filters_btn_color`、`sort_by_btn_color` をテーマ設定に用意しておく必要がある。
注意点
価格フィルターはアクティブ判定の計算ロジックが異なるため、min_value.value と range_max を比較して有効化を判定する。その他フィルターは active_values.size で個数をカウント。Bootstrap 5 のオフキャンバス・ドロップダウン機能が必須なので、テーマに bootstrap.bundle.js が読み込まれていることを確認する。svg-icons スニペットが存在しない場合は別のアイコンセット(Font Awesome など)に置き換える。
タグ:collectionfiltersort-bybootstrapui-control

コード

66 行 / liquid
{% liquid 
  for filter in collection.filters
    if filter.type == "price_range"
      if filter.min_value.value > 0 or filter.max_value.value < filter.range_max
        assign active_filter_values = 1 | plus: active_filter_values
      endif
    else
      assign active_filter_values = filter.active_values.size | plus: active_filter_values
    endif
  endfor
%}

<div class="collection-utilities mb-5 {% unless section.settings.show_product_count %}justify-content-end{% endunless %}">
  {% if section.settings.show_product_count %}
    <p class="collection-product-count small mb-0">
      {{ 'collection.count_products' | t: count: collection.products_count }}
    </p>
  {% endif %}
  {% if section.settings.show_filters or section.settings.show_sort_by %}
    <div class="d-flex align-items-center mx-n2">
      {% if section.settings.show_filters %}
        <button 
          class="btn btn-sm mx px-4 mx-2 {{ section.settings.filters_btn_color }}" 
          type="button" 
          data-bs-toggle="offcanvas" 
          data-bs-target="#offcanvas-collection-filters"
          aria-controls="offcanvas-collection-filters">
          <span class="d-flex align-items-center">
            {% render 'svg-icons', icon: 'filter', size: 16, class: 'me-3' %}
            {{ 'collection.filters.btn_text' | t }}
            {% if active_filter_values > 0 %}
              ({{ active_filter_values }})
            {% endif %}
          </span>
        </button>
      {% endif %}
      {% if section.settings.show_sort_by %}
        <sort-by class="sort-by dropdown">
          <button 
            class="btn btn-sm px-4 dropdown-toggle mx-2 {{ section.settings.sort_by_btn_color }}" 
            type="button" 
            data-bs-toggle="dropdown" 
            aria-expanded="false">
            {{ 'collection.sort_by' | t }}
          </button>
          <ul class="dropdown-menu dropdown-menu-end">
            {% for option in collection.sort_options %}
              <li>
                <input 
                  type="radio" 
                  class="btn-check" 
                  name="sort_by" 
                  id="sort-by-{{ option.value }}" 
                  value="{{ option.value }}"
                  {% if option.value == collection.sort_by %}checked{% endif %}>
                <label class="dropdown-item" for="sort-by-{{ option.value }}">
                  {{ option.name }}
                </label>
              </li>
            {% endfor %}
          </ul>
        </sort-by>
      {% endif %}
    </div>
  {% endif  %}
</div>

出典・ライセンス

License:
MIT

このコードは kondasoft 著作の MIT ライセンスソースです。 原本の著作権は kondasoft が保有します。日本語訳は 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