Analysis of PHP functions used to search templates in WordPress

Source: Internet
Author: User
: 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.

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.