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.
Example
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.
- If the document Category ID is 4, WordPress will find this file :?Category-4.php.
- If this file is not available, WordPress will find a general document classification template ,?Category. php.
- If this does not exist, WordPress will find a general article archive template ,?Archive. php.
- If not, WordPress returns to the main theme template file ,?Index. php.
If a visitor visits your homepage :?Http://example.com/blog/:
- Is WordPress Available first? Static homepage. If yes? Load the page at the template level.
- If there is no static homepage, go?Home. php?, Use it to generate the requested page.
- If?Home. php? No. go back toIndex. php? File to generate a page.
Overview
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.
-
- Front-page.php? -Used for setting the latest article or static page? ->? Read the homepage of the chapter
- Page display rules? -When set? ->? It is valid when the homepage displayed on the homepage is set in the read section.
- 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
-
- Single-{post_type}. php? -If the document type is? If it is a product, WordPress will findSingle-product.php.
- Single. php
- Index. php
Page display
Rendering a static page template file (Page? Post-type)
-
- Custom template file? -Page template? Page of assignment. see? Get_page_templates ().
- Page-{slug}. php? -If the page isRecent-news, WordPress will findPage-recent-news.php
- Page-{id}. php? -If the page ID is?6, WordPress will find and use?Page-6.php
- Page. php
- Index. php
Category display
Used to render a template file for a classification archiving page
-
- Category-{slug}. php? -If the category isNews, WordPress will findCategory-news.php
- Category-{id}. php? -If the category ID is?6, WordPress will findCategory-6.php
- Category. php
- Archive. php
- Index. php
Label display
The template file used to display the tag archiving page
-
- Tag-{slug}. php? -If the label isSometag, WordPress will find?Tag-sometag.php
- Tag-{id}. php? -If the tag ID is6, WordPress will findTag-6.php
- Tag. php
- Archive. php
- Index. php
Display custom terms
Template file used to render custom terms on the archive page
-
- 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
- Taxonomy-{taxonomy}. php? -If the term isSometax, WordPress will find?Taxonomy-sometax.php
- Taxonomy. php
- Archive. php
- Index. php
Display custom document types
Used to render the archive homepage template file of the custom document type
-
- Archive-{post_type}. php? -If? Document type? Yes?Product, WordPress will findArchive-product.php.
- Archive. php
- 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
-
- Author-{nicename}. php? -If the nickname of the author isRami, WordPress will find?Author-rami.php.
- Author-{id}. php? -If the author ID is6, WordPress will findAuthor-6.php.
- Author. php
- Archive. php
- Index. php
Date display
Used to render template files of the date-based archive homepage
-
- Date. php
- Archive. php
- Index. php
Search Result Display
Template file used to render the search result homepage
-
- Search. php
- Index. php
404 (not found) displayed
Template file used to render server 404 error pages
-
- 404. php
- Index. php
Attachment display
Used to render a single attachment (Attachment? Post-type) template file of the page
-
- MIME_type.php? -Can it be any MIME type? (Image. php,?Video. php,?Application. php).?Text/plainThe order is:
- Text. php
- Plain. php
- Text_plain.php
- Attachment. php
- Single-attachment.php
- Single. php
- 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
Example
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' );
SOURCE file
- The template-level function is defined in?
Wp-schemdes/theme. php
.
- The template loading level is defined in?
Wp-des/template-loader.php in
.