Liquid Snippets by ALSEL
📄 ページテンプレート初級

ブログページのヘッダー

ブログページの上部に表示するヘッダーセクション。背景画像とオーバーレイ、ブログタイトル、説明文を配置し、色・間隔・ボーダーをテーマカスタマイザーで調整できる。

用途
ブログ一覧ページ(blog テンプレート)の最上部に配置し、ブログ全体の視覚的な顔となるヘッダー領域を構築する。
設置場所
sections/blog-header.liquid に配置し、templates/blog.liquid の先頭で `{% section 'blog-header' %}` で読み込む。テーマカスタマイザー上でセクション追加時に自動表示される。
注意点
背景画像のアスペクト比が `section.settings.img.aspect_ratio` に依存するため、Shopify 管理画面で画像を正方形または 16:9 など標準比率でアップロードしておく。オーバーレイの色・ぼかし・不透明度は CSS 変数で動的に変わるため、ブラウザ開発者ツールの :root スコープでカスタムプロパティが正しく反映されているか確認する。コンテナ max-width がデフォルト 600px で固定されているため、テンプレート全体の幅に合わせて調整する必要がある。
タグ:blogheaderimage-overlayspacingcustomization

コード

282 行 / liquid
<header 
  id="blog-header-{{ section.id }}"
  class="
    blog-header image-overlay
    {{ 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.pt | prepend: 'pt-' }} 
    {{ section.settings.pb | prepend: 'pb-' }}
    {{ section.settings.pt_desktop | prepend: 'pt-desktop-' }} 
    {{ section.settings.pb_desktop | prepend: 'pb-desktop-' }}
  "
  style="
    --bs-bg-opacity: {{ section.settings.bg_opacity | append: '%' }};
    --bs-border-opacity: {{ section.settings.border_opacity | append: '%' }};
  ">
  {% unless section.settings.img == blank %}
    <div 
      class="img-wrapper"
      style="
        --overlay-color-rgb: {{ section.settings.img_overlay_color | color_to_rgb | remove: 'rgb(' | remove: ')' }};
        --overlay-opacity: {{ section.settings.img_overlay_opacity | append: '%' }};
        --overlay-blur: {{ section.settings.img_overlay_blur | append: 'px' }}
      ">
      <img
        srcset="{{ section.settings.img | image_url: width: 800 }} 800w, {{ section.settings.img | image_url: width: 1600 }} 1600w"
        src="{{ section.settings.img | image_url: width: 1600 }}"
        class="img-fluid"
        alt="{{ section.settings.img.alt }}"
        width="1600"
        height="{{ 1600 | divided_by: section.settings.img.aspect_ratio }}"
        loading="eager">
      </div>
  {% endunless %}
  <div 
    class="container"
    style="max-width: {{ section.settings.container_max_width | append: 'px' }};">
    <h2 class="title {{ section.settings.title_font_size }}">
      <span>{{ blog.title }}</span>
    </h2>
    {% unless section.settings.description == blank %}
      <div class="description rte mb-0 {{ section.settings.description_font_size }}">
        {{ section.settings.description }}
      </div>
    {% endunless %}
  </div>
</header>

{% schema %}
{
  "name": "Blog header",
  "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": "Image"
    },
    {
      "type": "image_picker",
      "id": "img",
      "label": "Image"
    },
    {
      "type": "checkbox",
      "id": "img_show",
      "label": "Show collection image",
      "default": true
    },
    {
      "type": "color",
      "id": "img_overlay_color",
      "label": "Overlay color",
      "default": "#000000"
    },
    {
      "type": "range",
      "id": "img_overlay_opacity",
      "label": "Overlay opacity",
      "min": 0,
      "max": 100,
      "step": 10,
      "default": 30,
      "unit": "%"
    },
    {
      "type": "range",
      "id": "img_overlay_blur",
      "label": "Overlay blur",
      "min": 0,
      "max": 10,
      "step": 1,
      "default": 0
    },
    {
      "type": "header",
      "content": "Text"
    },
    {
      "type": "select",
      "id": "title_font_size",
      "label": "Title font-size",
      "default": "h2",
      "options": [
        { "value": "h1", "label": "H1" },
        { "value": "h2", "label": "H2" },
        { "value": "h3", "label": "H3" },
        { "value": "h4", "label": "H4" },
        { "value": "h5", "label": "H5" },
        { "value": "h6", "label": "H6" }
      ]
    },
    {
      "type": "richtext",
      "id": "description",
      "label": "Description (optional)",
      "default": "<p>Add on optional description for this blog</p>"
    },
    {
      "type": "select",
      "id": "description_font_size",
      "label": "Description font-size",
      "default": "fs-md",
      "options": [
        { "value": "fs-sm", "label": "sm" },
        { "value": "fs-md", "label": "md" },
        { "value": "fs-lg", "label": "lg" },
        { "value": "fs-xl", "label": "xl" },
        { "value": "fs-xxl", "label": "xxl" }
      ]
    },
    {
      "type": "header",
      "content": "Spacing - mobile"
    },
    {
      "type": "range",
      "id": "pt",
      "label": "Top",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 8
    },
    {
      "type": "range",
      "id": "pb",
      "label": "Bottom",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 8
    },
    {
      "type": "header",
      "content": "Spacing - desktop"
    },
    {
      "type": "range",
      "id": "pt_desktop",
      "label": "Top",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 14
    },
    {
      "type": "range",
      "id": "pb_desktop",
      "label": "Bottom",
      "min": 0,
      "max": 20,
      "step": 1,
      "default": 14
    }
  ],
  "templates": ["blog"],
  "presets": [
    {
      "name": "Blog header"
    }
  ]
}
{% endschema %}

出典・ライセンス

License:
MIT

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