locate_template
函数
locate_template ( $template_names, $load = false, $require_once = true, $args = array() )
- 参数
-
-
(string|array)
$template_names
Template file(s) to search for, in order.- Required: 是
-
(bool)
$load
If true the template file will be loaded if it is found.- Required: 否
- Default: false
-
(bool)
$require_once
Whether to require_once or require. Has no effect if `$load` is false. Default true.- Required: 否
- Default: true
-
(array)
$args
Optional. Additional arguments passed to the template. Default empty array.- Required: 否
- Default: array()
-
(string|array)
- 返回值
-
- (string) The template filename if one is located.
- 定义位置
-
-
wp-includes/template.php
, line 699
-
wp-includes/template.php
- 引入
- 2.7.0
- 弃用
- –
Retrieves the name of the highest priority template file that exists.
Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat
so that themes which inherit from a parent theme can just overload one file.
function locate_template( $template_names, $load = false, $require_once = true, $args = array() ) {
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( ! $template_name ) {
continue;
}
if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
$located = STYLESHEETPATH . '/' . $template_name;
break;
} elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
$located = TEMPLATEPATH . '/' . $template_name;
break;
} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
$located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
break;
}
}
if ( $load && '' !== $located ) {
load_template( $located, $require_once, $args );
}
return $located;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


