WordPress 主題開發一般需要的模板都比較固定,比如主頁 (index.php,home.php),404 頁面 (404.php),搜索頁面 (search.php) 等,下面是來自 WordPress 官網的模板層級圖表:

圖表中包含了模板文件, 包含相關模板標籤與 CSS 樣式.

首頁模板
首頁模板一般用於展示最新文章列表等。
home.php
index.php
前台頁面展示 (Front Page display)
模板文件用於呈現站點首頁,首頁是否顯示博客的一個靜態頁面。前台頁面的模板優先於 index.php 與 home.php 模板。
front-page.php – 用於你最新的文章或者一個靜態頁面設置,設置方法:進入後台=》 設置=》 閲讀
文章詳情頁 (Single Post display)

文章詳情頁設置

single-{post_type}.php – post_type 可以設置不同的文章類型。
single.php
index.php

頁面展示 (Page display)

頁面模板文件可以展示一個自定義的獨立頁面

page-{slug}.php – 設置不同的頁面
page-{id}.php – 如果文章 id 為 6, WordPress 將讀取頁面模板 page-6.php
page.php
index.php

分類頁面展示 (Category display)

分類模板頁面用於讀取不同分類的文章

category-{slug}.php – 如果分類別名為 news, WordPress 將使用模板 category-news.php
category-{id}.php – 如果分類的 ID 為 6, WordPress 將使用模板 category-6.php
category.php
archive.php
index.php

標籤頁面展示 (Tag display)

標籤頁面用於展示標籤的文章列表

tag-{slug}.php -如果別名為 sometag, WordPress 會使用模板 tag-sometag.php
tag-{id}.php – 如果標籤的ID為 6, WordPress 使用的模板將是 tag-6.php
tag.php
archive.php
index.php

自定義分類展示 (Custom Taxonomies display)

自定義類型文件模板用於不同類型的的文章展示,比如日期規定頁面,作者歸檔頁面等。

taxonomy-{taxonomy}-{term}.php – 如果分類的類型是是 sometax, 而且該類型下的分類名為 term,WordPress 將會調用模板 taxonomy-sometax-someterm.php.
taxonomy-{taxonomy}.php -如果分類的類型是是 sometax, WordPress 將調用模板 taxonomy-sometax.php
taxonomy.php
archive.php
index.php

自定義文章類型展示 (Custom Post Types display)
自定義文章頁面是根據不同類型的文章如果圖片,視頻,音樂等讀取不同的模板。
archive-{post_type}.php – 如果文章類型為 product, WordPress 將調用模板 archive-product.php.
archive.php
index.php

作者頁面展示 (Author display)

作者頁面用於展示指定作者的文章列表

author-{nicename}.php -如果作者的名字為 rami, WordPress 將調用模板 author-rami.php.
author-{id}.php – 如果作者的 ID 為 6, WordPress 將調用 author-6.php.
author.php
archive.php
index.php

日期頁面展示 (Date display)

日期頁面模板用於按日期的文章歸的模板

date.php
archive.php
index.php
搜索結果頁面 (Search Result display)

搜索結果頁面用於展示系統的搜索結果

search.php
index.php

404 (Not Found) 頁面

404 頁面用於展示系統返回 404 錯誤的展示頁面

404.php
index.php

附件頁面展示 (Attachment display)

附件頁面用於展示不同附件的列表頁

MIME_type.php – 不同類型的附件模板 (image.php, video.php, application.php). For text/plain, in order:
text.php
plain.php
text_plain.php
attachment.php
single-attachment.php
single.php
index.php
模板篩選
WordPress 中你可以通過函數 get_query_template()來篩選不同的模板 模板格式為:」{$type}_template.php」 , 完整列表如下:

  • index_template
  • 404_template
  • archive_template
  • author_template
  • category_template
  • tag_template
  • taxonomy_template
  • date_template
  • home_template
  • front_page_template
  • page_template
  • paged_template
  • search_template
  • single_template
  • text_template, plain_template, text_plain_template (all mime types)
  • attachment_template
  • comments_popup