https://wordpress-web.and-ha.com/template-hierarchy
 
トップページ(ホームページ)表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | front-page.php | 
| 3 | home.php | 
| 4 | index.php | 
個別投稿表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | single-[post_type].php | 
| 2 | single.php | 
| 3 | singular.php | 
| 4 | index.php | 
固定ページ表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | カスタムテンプレート名.php | 
| 2 | page-[slug].php | 
| 3 | page-[ID].php | 
| 4 | page.php | 
| 5 | singular.php | 
| 6 | index.php | 
カテゴリー表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | category-[slug].php | 
| 2 | category-[ID].php | 
| 3 | category.php | 
| 4 | archive.php | 
| 5 | index.php | 
タグ表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | tag-[slug].php | 
| 2 | tag-[ID].php | 
| 3 | tag.php | 
| 4 | archive.php | 
| 5 | index.php | 
カスタムタクソノミー表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | taxonomy-[taxonomy]-[teram].php | 
| 2 | taxsonomy-[taxsonomy].php | 
| 3 | taxsonomy.php | 
| 4 | archive.php | 
| 5 | index.php | 
カスタム投稿タイプ表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | archive-[post_type].php | 
| 2 | archive.php | 
| 3 | index.php | 
作成者表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | author-[name].php | 
| 2 | author-[ID].php | 
| 3 | author.php | 
| 4 | archive.php | 
| 5 | index.php | 
日付別表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | date.php | 
| 2 | archive.php | 
| 3 | index.php | 
検索結果表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | search.php | 
| 2 | index.php | 
404エラー表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | 404.php | 
| 2 | index.php | 
添付ファイル表示
| 優先順位 | テンプレートファイル名 | 
|---|
| 1 | MIME_TYPE.php | 
| 2 | attachment.php | 
| 3 | single.php | 
| 4 | index.php | 
テンプレート階層とは?
「テンプレート階層」とは、WordPressが定めたテンプレートファイルを出力する際の仕組み・ルールのことです。
ページごとに、どのテンプレートファイルを呼び出すか優先順位が決まっています。
優先順位
- アクセスされたURLからページの種類を判別
- ページの種類ごと(TOPページなのか?固定ページなのか?)にテンプレート階層上位のテンプレートファイルから探す
- 探していく中で、一致するテンプレートファイルがあったらそのテンプレートファイルを使用
- 一致するテンプレートファイルがなければ、階層内の次のテンプレートファイルを探す
- 結局どれにも一致するテンプレートファイルがなかった場合、「index.php」を使用する
例えば、、、
サイトのトップページを開いた場合、font-page.php優先順位が最も高くなり、そして次にhome.phpが映され、最後にindex.phpが反映されます。
「ファイルある→ない→ある→ない→ある」と、どんどんスキップされていくイメージです。
どのページも最終的にはindex.phpが反映されます。つまり、WordPressは極端に言うとindex.phpさえあれば、全てのページを表示させることができます。
WordPress公式の外観図
よく見るのがWordPress公式から配布されている下記画像です。
左から右にWordPress側が読み込んでいきます。
 画像引用:wordpress.org テンプレート階層より(テンプレート階層 – Japanese Team – WordPress.org 日本語)
画像引用:wordpress.org テンプレート階層より(テンプレート階層 – Japanese Team – WordPress.org 日本語)
「テンプレート階層」についてのWordPress公式ページ
テンプレート階層 – Japanese Team – WordPress.org 日本語