Liquid Snippets by ALSEL
🧭 ヘッダー/フッター/ナビゲーション中級

アナウンスメントバー(カルーセル表示)

ストア上部に複数のお知らせを自動回転で表示するセクション。背景色、テキスト色、ボーダー、フォントサイズなどを管理画面でカスタマイズでき、複数のスライドを自動再生またはボタン操作で切り替える。

用途
セール予告、配送情報、キャンペーン告知など重要なお知らせをストア最上部に掲載するとき。複数のお知らせを持つ場合、カルーセル形式で順番に表示できる。
設置場所
sections/announcement-bar.liquid に配置し、theme.liquid の <body> 最上部または {% section 'announcement-bar' %} で呼び出す。管理画面のセクション追加画面から「Announcement bar」を選んで使用。
注意点
自動再生間隔は 0 秒で無効化、1~10秒で設定でき、ブロックが1つだけの場合は左右ナビボタンが非表示になる。container_max_width は空白のままでグローバル幅を継承できるが、数値を入れるとその値がピクセル単位で固定される。テーマカスタマイザーでスライドを選択すると、Bootstrap の Carousel インスタンスを通じて対応スライドにジャンプする。背景グラデーションと不透明度は CSS 変数(--bs-bg-opacity、--bs-border-opacity)で制御するため、通常の opacity 指定とは別に機能する。
タグ:announcementcarouselheaderbootstrapcustomizablesection

コード

310 行 / liquid
<section 
  id="announcement-bar-{{ section.id }}" 
  class="
    announcement-bar 
    {{ section.settings.bg_color }} 
    {{ section.settings.bg_gradient }}
    {{ section.settings.text_color }}
    {{ section.settings.border_top_width | prepend: 'border-top-' }}
    {{ section.settings.border_bottom_width | prepend: 'border-bottom-' }}
    {{ section.settings.border_color }} 
    {{ section.settings.font_size }} 
    {{ section.settings.font_size_desktop }} 
    {{ section.settings.text_transform }} 
    {{ section.settings.letter_spacing | prepend: 'ls-' }} 
  "
  style="
    --bs-bg-opacity: {{ section.settings.bg_opacity | append: '%' }};
    --bs-border-opacity: {{ section.settings.border_opacity | append: '%' }};
  ">
  <div class="container">
    <div 
      id="carousel-{{ section.id }}" 
      class="carousel slide " 
      data-bs-ride="{% if section.settings.carousel_autoplay > 0 %}carousel{% else %}false{% endif %}"
      data-bs-interval="{{ section.settings.carousel_autoplay | times: 1000 }}"
      aria-label="{{ 'general.accessibility.announcements' | t }}"
      style="max-width: {{ section.settings.container_max_width }}px;">
      <div class="carousel-inner">
        {% for block in section.blocks %}
          <div 
            class="
              carousel-item 
              {{ section.settings.pt | prepend: 'pt-' }} 
              {{ section.settings.pb | prepend: 'pb-' }}
              {% if forloop.first %}active{% endif %}
            " 
            data-index="{{ forloop.index0 }}" 
            {{ block.shopify_attributes }}>
            <div class="description rte lh-sm">
              {{ block.settings.announcement }}
            </div>
          </div>
        {% endfor %}
      </div>
      {% if section.blocks.size > 1 %}
        <button 
          class="carousel-control carousel-control-prev" 
          type="button" 
          data-bs-target="#carousel-{{ section.id }}" 
          data-bs-slide="prev"
          aria-label="{{ 'general.accessibility.previous' | t }}">
          {% render 'svg-icons', icon: 'chevron-left', size: 22 %}
        </button>
        <button 
          class="carousel-control carousel-control-next" 
          type="button" 
          data-bs-target="#carousel-{{ section.id }}" 
          data-bs-slide="next"
          aria-label="{{ 'general.accessibility.next' | t }}">
          {% render 'svg-icons', icon: 'chevron-right', size: 22 %}
        </button>
      {% endif %}
    </div>
  </div>
</section>

{% if request.design_mode %}
  <script>
    document.addEventListener('shopify:block:select', (event) => {
      const carousel = event.target.closest('#carousel-{{ section.id }}')
    
      if (carousel) {
        bootstrap.Carousel.getOrCreateInstance(carousel, { ride: false })
          .to(event.target.dataset.index)
      }
    })
  </script>
{% endif %}

{% schema %}
{
  "name": "Announcement bar",
  "settings": [
    {
      "type": "header",
      "content": "Styling"
    },
    {
      "type": "select",
      "id": "bg_color",
      "label": "Background color",
      "default": "bg-body",
      "options": [
        { "value": "bg-primary", "label": "Primary" },
        { "value": "bg-secondary", "label": "Secondary" },
        { "value": "bg-body", "label": "Body" },
        { "value": "bg-white", "label": "White" }
      ]
    },
    {
      "type": "range",
      "id": "bg_opacity",
      "label": "Background opacity",
      "min": 0,
      "max": 100,
      "step": 1,
      "default": 100,
      "unit": "%"
    },
    {
      "type": "select",
      "id": "bg_gradient",
      "label": "Background gradient",
      "options": [
        { "value": "bg-gradient", "label": "Yes" },
        { "value": "", "label": "No" }
      ],
      "default": ""
    },
    {
      "type": "select",
      "id": "text_color",
      "label": "Text color",
      "default": "text-body",
      "options": [
        { "value": "text-primary", "label": "Primary" },
        { "value": "text-secondary", "label": "Secondary" },
        { "value": "text-body", "label": "Body" },
        { "value": "text-white", "label": "White" }
      ]
    },
    {
      "type": "range",
      "id": "border_top_width",
      "label": "Border top width",
      "default": 0,
      "min": 0,
      "max": 16,
      "step": 1,
      "unit": "px"
    },
    {
      "type": "range",
      "id": "border_bottom_width",
      "label": "Border bottom width",
      "default": 0,
      "min": 0,
      "max": 16,
      "step": 1,
      "unit": "px"
    },
    {
      "type": "select",
      "id": "border_color",
      "label": "Border color",
      "default": "border-body",
      "options": [
        { "value": "border-primary", "label": "Primary" },
        { "value": "border-secondary", "label": "Secondary" },
        { "value": "border-body", "label": "Body" },
        { "value": "border-white", "label": "White" }
      ]
    },
    {
      "type": "range",
      "id": "border_opacity",
      "label": "Border opacity",
      "min": 0,
      "max": 100,
      "step": 1,
      "default": 100,
      "unit": "%"
    },
    {
      "type": "text",
      "id": "container_max_width",
      "label": "Container max-width (px)",
      "info": "Leave empty to use the global container width",
      "default": "600"
    },
    {
      "type": "header",
      "content": "General"
    },
    {
      "type": "select",
      "id": "font_size",
      "label": "Font size - mobile",
      "default": "fs-sm",
      "options": [
        { "value": "fs-xs", "label": "xs" },
        { "value": "fs-sm", "label": "sm" },
        { "value": "fs-md", "label": "md" },
        { "value": "fs-lg", "label": "lg" },
        { "value": "fs-xl", "label": "xl" }
      ]
    },
    {
      "type": "select",
      "id": "font_size_desktop",
      "label": "Font size - desktop",
      "default": "fs-desktop-sm",
      "options": [
        { "value": "fs-desktop-xs", "label": "xs" },
        { "value": "fs-desktop-sm", "label": "sm" },
        { "value": "fs-desktop-md", "label": "md" },
        { "value": "fs-desktop-lg", "label": "lg" },
        { "value": "fs-desktop-xl", "label": "xl" }
      ]
    },
    {
      "type": "select",
      "id": "text_transform",
      "label": "Text transform",
      "default": "text-capitalize",
      "options": [
          { "value": "", "label": "Normal" },
          { "value": "text-capitalize", "label": "Capitalize" },
          { "value": "text-lowercase", "label": "Lowercase" },
          { "value": "text-uppercase", "label": "Uppercase" }

      ]
    },
    {
      "type": "range",
      "id": "letter_spacing",
      "label": "Letter spacing",
      "default": 0,
      "min": 0,
      "max": 5
    },
    {
      "type": "header",
      "content": "Carousel"
    },
    {
      "type": "range",
      "id": "carousel_autoplay",
      "label": "Autoplay",
      "min": 0,
      "max": 10,
      "default": 5,
      "unit": "sec",
      "info": "Selecing \"0\" will disable autoplay."
    },
    {
      "type": "checkbox",
      "id": "carousel_vertical",
      "label": "Vertical sliding",
      "info": "NOTE: This feature is supported only in our Premium Shopify Themes. [Browse premium themes](https://www.kondasoft.com/collections/shopify-themes)",      
      "default": true
    },
    {
      "type": "header",
      "content": "Spacing"
    },
    {
      "type": "range",
      "id": "pt",
      "label": "Top",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 3
    },
    {
      "type": "range",
      "id": "pb",
      "label": "Padding bottom",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 3
    }
  ],
  "blocks": [
    {
      "type": "slide",
      "name": "Slide",
      "settings": [
        {
          "type": "inline_richtext",
          "id": "announcement",
          "label": "Announcement",
          "default": "Announce something important here"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Announcement bar",
      "blocks": [
        {
          "type": "slide",
          "settings": {
            "announcement": "Announce something important here"
          }
        },
        {
          "type": "slide",
          "settings": {
            "announcement": "Free shipping over $100 USD"
          }
        }
      ]
    }
  ]
}
{% endschema %}

出典・ライセンス

License:
MIT

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

関連項目

🧭 ヘッダー/フッター/ナビゲーション中級

Alpine.js統合のメニュー開閉

Alpine.js の @click ディレクティブと :class バインディングを使ったメニュー開閉コンポーネント。ボタンクリックで open 状態を切り替え、ul 要素に expanded クラスを条件付きで付与する。

📁 theme-tools·MIT·5
🧭 ヘッダー/フッター/ナビゲーション初級

ヘッダーのレイアウト構造

Web Component のカスタムエレメント `<c-header>` でラップしたヘッダー要素。Tailwind CSS のユーティリティクラスを使い、レスポンシブなパディングとフレックスボックスレイアウトを実装している。

📁 theme-tools·MIT·14
🧭 ヘッダー/フッター/ナビゲーション初級

ナビゲーションバーのロゴ

ストアのロゴをナビゲーションバーに表示し、クリックでホームページに戻るコンポーネント。ロゴ画像がない場合はストア名をテキストで表示する。

📁 ks-bootshop·MIT·18
🧭 ヘッダー/フッター/ナビゲーション初級

決済方法アイコン

ストアで有効な決済手段のアイコンをリスト表示するスニペット。Shopify が提供する `payment_type_svg_tag` フィルタを使い、クレジットカード・Apple Pay・Google Pay などのロゴを自動的に描画する。

📁 ks-bootshop·MIT·18
🧭 ヘッダー/フッター/ナビゲーション初級

グローバルナビゲーションメニュー

Shopify 管理画面の「メインメニュー」リンクリストをループし、トップレベルメニュー + 1階層のサブメニューを描画するスニペット。link.title と sub_link.title を escape フィルターでエスケープして XSS 対策を施している。

📁 shopify-theme-lab·MIT·19
🧭 ヘッダー/フッター/ナビゲーション初級

フッター

ストア共通のフッターセクション。管理画面で設定したフッターメニュー(リンクリスト)をループ表示し、著作権表記を出す。

📁 shopify-theme-lab·MIT·25