get_query_template()
get_query_template( string $type, array $templates = ar…
get_query_template( string $type, array $templates = array() )
检索模板的路径
Retrieve path to a template
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
用于快速检索模板的路径,而不包括文件扩展名。如果文件存在,它还将使用locate_template()检查父主题。允许更通用的模板位置,而不使用其他getu template()函数。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $type | (string) | 必需 | 不带扩展名的文件名。 |
| $templates | (array) | 可选 | 候选模板的可选列表 |
返回(Return)
(string)模板文件的完整路径。
源码(Source)
/**
* Retrieve path to a template
*
* Used to quickly retrieve the path of a template without including the file
* extension. It will also check the parent theme, if the file exists, with
* the use of {@link locate_template()}. Allows for more generic template location
* without the use of the other get_*_template() functions.
*
* @since 1.5.0
*
* @param string $type Filename without extension.
* @param array $templates An optional list of template candidates
* @return string Full path to template file.
*/
function get_query_template( $type, $templates = array() ) {
$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
if ( empty( $templates ) )
$templates = array("{$type}.php");
$template = locate_template( $templates );
/**
* Filter the path of the queried template by type.
*
* The dynamic portion of the hook name, `$type`, refers to the filename -- minus the file
* extension and any non-alphanumeric characters delimiting words -- of the file to load.
* This hook also applies to various types of files loaded as part of the Template Hierarchy.
*
* @since 1.5.0
*
* @param string $template Path to the template. See locate_template().
*/
return apply_filters( "{$type}_template", $template );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.5.0 | wp-includes/template.php:23 | 18 | 4 |
笔记(Notes)
例子
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!