locate_template()判断模版文件是否存在,存在则返回模版路径

目录

描述

Retrieve the name of the highest priority template file that exists, optionally loading that file.

Searches STYLESHEETPATH before TEMPLATEPATH, so themes which inherit from a parent can overload one file.

locate_template() 描述

用法

<?php locate_template$template_names$load$require_once ?>

locate_template() 用法

参数

$template_names

(array) (必填) Array of template files to search for, in priority order. (Requires file extension.)

默认值: None

$load

(boolean) (可选) If true, the template file will be loaded, if it is found.

默认值: false

$require_once

(boolean) (可选) If true, the template file will be loaded with the php require_once function. If false, the template file will be loaded with the php require function. This parameter has no effect if $load is false.

默认值: true

locate_template() 参数

返回值

(string) 

The template filename, if one is located, an empty string, if not.

locate_template() 返回值

示例

Load a specific template part based on the current pagename:

locate_template() 示例

历史

添加于 版本: 2.7.0

locate_template() 历史

源文件

locate_template() 函数的代码位于 wp-includes/template.php.

locate_template() 源文件