: This article mainly introduces the parsing of PHP functions used to search templates in WordPress. if you are interested in PHP tutorials, refer to it. Locate_template () is used to retrieve the template files with the highest priority, and directly load the template files.
When using the locate_template () function to retrieve a parent topic, if a subtopic exists, the template of the subtopic is preferentially used.
Usage
locate_template( $template_names, $load, $require_once );
Parameters
$ Template_names
(Array) (required) the template file name to be introduced (requires the extension) will match the existence of files one by one based on the array, the higher the priority of the front edge.
Default value: None
$ Load
(Boolean) (optional) if set to True, the template file is directly introduced.
Default value: False
$Require_ Once
(Boolean) (optional) if it is set to True (Require_ Once). Otherwise, it will be introduced no matter whether it has been introduced or not (Require).
(This parameter takes effect only when $ load is set to True ).
Default value: False
Return value
(String) if a specified template file exists, its path is returned. Otherwise, an empty string is returned.
Example
If (locate_template ('content-'. $ pageName.'. php ')! = '') {// Yes. the template file get_template_part ('content', $ pageName);} else {// does not exist. the content the_content ();} is directly displayed ();}
Others
This function is located in: wp-includes/template. php
Quick search template
Get_query_template () is used to quickly retrieve the page template, and you need to follow the predefined page type (type ).
It differs from locate_template () in that you need to fill in the page type and generate the {$ type} _ template path filter.
Usage
get_query_template( $type, $templates );
Parameters
$ Type
(String) (required) type of the page of the template file to be obtained. enter a file name (such as single) with no extension for the template file ).
Default value: None
$ Templates
(Array) (optional) list of optional templates.
Default value: empty array
Return value
Return the path of the template file.
Example
If yes, the 404 page template will be introduced:
if ( '' != get_404_template() ) include( get_404_template() );
Others
This function is located in: wp-includes/template. php
The above describes the parsing of PHP functions used to search templates in WordPress, including The require content, and hope to help those who are interested in PHP tutorials.