WordPress ブロックテーマのテンプレート階層
ブロックテーマ(FSE)の完全なテンプレート階層。リクエストの種類ごとに、WordPress が探すテンプレートを、最も具体的なものから index.html へのフォールバックまで順番に一覧化しました。クラシックの階層図に相当する、ブロック時代版です。
WordPress はリクエストごとに、これらのテンプレートを(最も具体的なものから)順番に探し、テーマの /templates フォルダー内で最初に見つかったものを使用して探索を止めます。この連鎖は必ず index.html で終わります。
フロントページ
サイトのフロントページ。最新の投稿を表示する設定でも、固定ページを指定している場合でも表示されます。
- front-page.html
- home.html
- index.html
front-page.html は「設定 → 表示設定」の選択に関わらず優先されます。フロントページが固定ページで front-page.html が存在しない場合は、home.html ではなく固定ページのチェーンにフォールバックします。
投稿一覧(ブログ)
最新の投稿を一覧表示するページ(「設定 → 表示設定」の「投稿ページ」)。
- home.html
- index.html
個別投稿
個々のブログ投稿。
- single-post-{slug}.html
- single-post.html
- single.html
- singular.html
- index.html
カスタム投稿タイプの個別ページ
カスタム投稿タイプの個々のエントリー(例:「book」)。
- single-{post-type}-{slug}.html
- single-{post-type}.html
- single.html
- singular.html
- index.html
スラッグが「dune」の投稿タイプ「book」の場合:single-book-dune.html、次に single-book.html、最後に single.html の順で解決されます。
固定ページ
通常の WordPress 固定ページ。
- page-{slug}.html
- page-{id}.html
- page.html
- singular.html
- index.html
カスタムテンプレートを適用した固定ページ
エディターの「テンプレート」パネルでカスタムテンプレートを割り当てた固定ページ。
- {custom-template}.html
- page-{slug}.html
- page-{id}.html
- page.html
- singular.html
- index.html
カスタムテンプレートは theme.json の customTemplates 配列で宣言し、/templates に配置します。割り当てたテンプレートは固定ページのチェーン全体よりも優先されます。
カテゴリーアーカイブ
1つのカテゴリーに属する投稿を一覧表示するアーカイブ。
- category-{slug}.html
- category-{id}.html
- category.html
- archive.html
- index.html
タグアーカイブ
1つのタグが付いた投稿を一覧表示するアーカイブ。
- tag-{slug}.html
- tag-{id}.html
- tag.html
- archive.html
- index.html
カスタムタクソノミーアーカイブ
カスタムタクソノミーのターム(term)のアーカイブ。
- taxonomy-{taxonomy}-{term}.html
- taxonomy-{taxonomy}.html
- taxonomy.html
- archive.html
- index.html
投稿者アーカイブ
1人の投稿者の投稿をまとめたアーカイブ。
- author-{nicename}.html
- author-{id}.html
- author.html
- archive.html
- index.html
日付アーカイブ
年/月/日ごとのアーカイブ。
- date.html
- archive.html
- index.html
投稿タイプアーカイブ
has_archive が設定されたカスタム投稿タイプのアーカイブインデックス。
- archive-{post-type}.html
- archive.html
- index.html
検索結果
サイト内検索の結果ページ。
- search.html
- index.html
404(ページが見つかりません)
URL に一致するコンテンツがない場合に表示されます。
- 404.html
- index.html
添付ファイルページ
個々のメディア添付ファイルのページ。
- attachment.html
- single.html
- singular.html
- index.html
多くのサイトでは添付ファイルページを完全に無効化しています(内容が薄いため)。有効にしている場合のチェーンは次のとおりです。
プライバシーポリシーページ
「設定」でサイトのプライバシーポリシーとして指定したページ。
- page-privacy-policy.html
- privacy-policy.html
- page.html
- singular.html
- index.html
従来の(PHP)階層との違い
- テンプレートはテーマルート直下の .php ファイルではなく、/templates 内の .html ファイルです。single.php は存在せず、single.html になります。
- 再利用可能な領域(ヘッダー、フッター)は /parts 内のテンプレートパーツであり、get_header() / get_footer() の PHP 呼び出しではなく wp:template-part ブロックで参照します。
- get_template_part() のチェーンも get_header()/get_footer() もありません。構成は .html ファイル内のテンプレートパーツブロックで行います。
- index.html は必須です。templates/index.html を持たない block theme は有効な block theme とはみなされません。これは上記すべてのルートに対する最終フォールバックとして必ず必要になります。
- テーマが block theme と判定されるのは、ヘッダーのフラグによってではなく、templates/index.html と theme.json が存在することによってです。
- これらのテンプレートはサイトエディター(外観 → エディター)で編集してデータベースに保存でき、その変更はカスタマイズを削除するまでテーマのファイルよりも優先されます。「テンプレートを変更しても何も反映されないのはなぜか」とデバッグしている人が戸惑うポイントです。