当前浏览:首页 / WordPress函数 / get_query_template()

get_query_template( string $type, string[] $templates = array() )

检索模板的路径

querymore...

templatemore...


描述

用于快速检索模板的路径,而不包括文件扩展名。如果文件存在,它还将使用locate_template()检查父主题。允许使用更通用的模板位置,而无需使用其他get_*_template()函数。


参数

$type

(string) (必填) 不带扩展名的文件名。

$templates

(string[]) (可选) 模板候选项的可选列表。

默认值: array()


返回

(string) 模板文件的完整路径。



源码

查看源码 官方文档


更新日志

版本描述
1.5.0开始引入

使用示例

  • 示例1

    示例

    可以与include()或require()一起使用以检索路径。

    if ( '' !== get_query_template( '404' ) ) {
    	include( get_query_template( '404' ) );
    }
    

    或者也可以通过

    if ( '' != get_404_template() ) {
    	include( get_404_template() );
    }