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