Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the PHP functions used to retrieve templates in WordPress

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the WordPress used to retrieve the template of the PHP function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.

Locate_template () is used to retrieve the highest priority template file that exists, and to load the template file directly.

When retrieving the locate_template () function, if there is a child topic, the template of the child topic is preferred, and the parent topic is no longer retrieved.

Usage

Locate_template ($template_names, $load, $require_once)

Parameters.

$template_names

(array) (required) the template file name to be introduced (requires an extension) will match the existence of the file one by one according to the array, the higher the priority.

Default value: None

$load

(Boolean) (optional) if set to True, the template file is introduced directly.

Default value: False

$require_once

(Boolean) (optional) if set to True, this time will not be introduced (require_once) if it has been introduced before, otherwise it will be introduced (require) regardless of whether it has been introduced or not.

(this parameter takes effect only if $load is True.)

Default value: False

Return value

(string) returns the path of a specified template file as long as it exists, otherwise an empty string is returned.

Examples

If (locate_template ('content-'. $pageName. ('.php')! =') {/ / exists and introduces the template file get_template_part ('content', $pageName);} else {/ / does not exist and displays the content the_content ();}

Other

This function is located at: wp-includes/template.php

Quick retrieval template

Get_query_template () is used to quickly retrieve the page template and needs to be based on the predetermined page type (type).

It differs from locate_template () in that it needs to fill in the type of page and generates a {$type} _ template template path filter.

Usage

Get_query_template ($type, $templates)

Parameters.

$type

(string) (required) the type of page of the template file to be obtained, fill in the file name of the corresponding template file that does not have an extension (such as single).

Default value: None

$templates

(array) (optional) list of alternative templates.

Default value: empty array

Return value

Returns the path to the template file.

Examples

If present, introduce a template for the 404 page:

If ('! = get_404_template ()) include (get_404_template ())

Other

This function is located at: wp-includes/template.php

Thank you for reading this article carefully. I hope the article "what are the PHP functions used to retrieve templates in WordPress" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report