Wordpress template level

Source: Internet
Author: User
Brief introduction WordPress templates are combined to generate the pages of your website. Some templates, such as headers and footers, are public to all pages, and some are used only in some specific pages/situations. This article is about: This article answers the following questions: What template file is called when WordPress generates a specific page? Who can this article be useful: since WordPress introduced the main introduction

WordPress templates are combined to generate the pages of your website. Some templates, such as headers and footers, are public to all pages, and some are used only in some specific pages/situations.

This article is about:

This article answers the following questions:

What template file is called when WordPress generates a specific page?

Who can this article be useful:

Since WordPress introduced a topic, templates become more and more configurable. to develop WordPress themes, you need to know how WordPress selects template files for different pages. If you want to customize an existing topic, this article will tell you which template files need to be modified.

Condition tag function judgment

WordPress provides multiple methods to match queries to templates. Topic developers can also use condition tags to control the use of templates on specific pages. Some Wordpress themes may not implement all the features mentioned here. Some topics use condition labels to load other template files. See the condition tag page and query-based topic development.

Basic concepts of layered structure of template files

WordPress uses the query string-the information contained in each link on your website to decide which template file to use or which template file to use.

First, wordpress matches all query strings to query the type-for example, it determines the type of page (search page, category page, home page, etc.) to be requested.

Then the template is selected-web page content generation-you can specify the order at the WordPress template level to determine the template files in a specific WordPress topic.

WordPress searches for the template file by a specific name in the current topic directory and matches the first template file listed by the current query condition.

IfIndex. php? With the exception of template files, topic developers can freely select the specific template files they want to implement. if WordPress cannot find a matching template file, it will jump to the next file name at the current level. if WordPress cannot find any matching template file,Index. php? The topic homepage template file will be used by default.


If your blog website is?Http://example.com/blog/?, A visitor clicks a link to a Category:Http://example.com/blog/category/your-cat/: WordPress searches for template files and generates pages as follows.

WordPress searches for a template file matching the Category ID of the current article in the current topic directory.

  1. If the document Category ID is 4, WordPress will find this file :?Category-4.php.
  2. If this file is not available, WordPress will find a general document classification template ,?Category. php.
  3. If this does not exist, WordPress will find a general article archive template ,?Archive. php.
  4. If not, WordPress returns to the main theme template file ,?Index. php.

If a visitor visits your homepage :?Http://example.com/blog/:

  1. Is WordPress Available first? Static homepage. If yes? Load the page at the template level.
  2. If there is no static homepage, go?Home. php?, Use it to generate the requested page.
  3. If?Home. php? No. go back toIndex. php? File to generate a page.

The following chart shows which template file is called at the WordPress template level to generate a WordPress page.

Template level details

The following sections describe the sequence in which template files of the query type are called through WordPress.

Homepage display

The template file used to render the homepage of a blog post, whether it is a site homepage or a static page. note: On the homepage, the homepage template takes precedence over the Index template of the blog post.

  1. Front-page.php? -Used for setting the latest article or static page? ->? Read the homepage of the chapter
  2. Page display rules? -When set? ->? It is valid when the homepage displayed on the homepage is set in the read section.
  3. What are the homepage display rules? -When set? ->? Effective when the published articles displayed on the homepage are set
Article page display

Template file used to render a single article page

  1. Single-{post_type}. php? -If the document type is? If it is a product, WordPress will findSingle-product.php.
  2. Single. php
  3. Index. php
Page display

Rendering a static page template file (Page? Post-type)

  1. Custom template file? -Page template? Page of assignment. see? Get_page_templates ().
  2. Page-{slug}. php? -If the page isRecent-news, WordPress will findPage-recent-news.php
  3. Page-{id}. php? -If the page ID is?6, WordPress will find and use?Page-6.php
  4. Page. php
  5. Index. php
Category display

Used to render a template file for a classification archiving page

  1. Category-{slug}. php? -If the category isNews, WordPress will findCategory-news.php
  2. Category-{id}. php? -If the category ID is?6, WordPress will findCategory-6.php
  3. Category. php
  4. Archive. php
  5. Index. php
Label display

The template file used to display the tag archiving page

  1. Tag-{slug}. php? -If the label isSometag, WordPress will find?Tag-sometag.php
  2. Tag-{id}. php? -If the tag ID is6, WordPress will findTag-6.php
  3. Tag. php
  4. Archive. php
  5. Index. php
Display custom terms

Template file used to render custom terms on the archive page

  1. Taxonomy-{taxonomy}-{term}. php? -If the term is?SometaxAnd the term category is?Someterm,What will WordPress search?Taxonomy-sometax-someterm.php.? As for the document format, the term is 'post _ format' and the category is 'post-format-{format}. example?Taxonomy-post_format-post-format-link.php
  2. Taxonomy-{taxonomy}. php? -If the term isSometax, WordPress will find?Taxonomy-sometax.php
  3. Taxonomy. php
  4. Archive. php
  5. Index. php
Display custom document types

Used to render the archive homepage template file of the custom document type

  1. Archive-{post_type}. php? -If? Document type? Yes?Product, WordPress will findArchive-product.php.
  2. Archive. php
  3. Index. php

(To render a single custom article type, refer to the above article page .)

Displayed by author

Used to render the template file of the author's archive homepage

  1. Author-{nicename}. php? -If the nickname of the author isRami, WordPress will find?Author-rami.php.
  2. Author-{id}. php? -If the author ID is6, WordPress will findAuthor-6.php.
  3. Author. php
  4. Archive. php
  5. Index. php
Date display

Used to render template files of the date-based archive homepage

  1. Date. php
  2. Archive. php
  3. Index. php
Search Result Display

Template file used to render the search result homepage

  1. Search. php
  2. Index. php
404 (not found) displayed

Template file used to render server 404 error pages

  1. 404. php
  2. Index. php
Attachment display

Used to render a single attachment (Attachment? Post-type) template file of the page

  1. MIME_type.php? -Can it be any MIME type? (Image. php,?Video. php,?Application. php).?Text/plainThe order is:
    1. Text. php
    2. Plain. php
    3. Text_plain.php
  2. Attachment. php
  3. Single-attachment.php
  4. Single. php
  5. Index. php
Filter level

The WordPress template system allows you to filter layers. filters (Get_query_template ()?) Use the filter name :?"{$ Type} _ template"??$ Type? Is the file name that removes the. php suffix in the hierarchy.

Complete List:

  • 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

For example, let's use the default author level:

  • Author-{nicename}. php
  • Author-{id}. php
  • Author. php

In orderAuthor-{role}. phpAddBefore author. php, we can operate on the actual usage level.? 'Author _ template' hook. This allows a request for/author/username where username has the role of editor to display using author-editor.php if present in the current themes directory.

function author_role_template( $templates='' ){$author = get_queried_object();$role=$author->roles[0];if(!is_array($templates) &&?!empty($templates)) {$templates=locate_template(array("author-$role.php",$templates),false);} elseif(empty($templates)) {$templates=locate_template("author-$role.php",false);}else {$new_template=locate_template(array("author-$role.php"));if(!empty($new_template)) array_unshift($templates,$new_template);}return $templates;}add_filter( 'author_template', 'author_role_template' );
  • The template-level function is defined in?Wp-schemdes/theme. php.
  • The template loading level is defined in?Wp-des/template-loader.php in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.