函数原型
get_page_template(): string
函数描述
Retrieves path of page template in current or parent template.
是否弃用
未弃用
函数参数
无
函数返回值
string Full path to page template file.
函数位置
File: wp-includes/template.php.
函数源码
function get_page_template() {
$id = get_queried_object_id();
$template = get_page_template_slug();
$pagename = get_query_var( 'pagename' );
if ( ! $pagename && $id ) {
// If a static page is set as the front page, $pagename will not be set.
// Retrieve it from the queried object.
$post = get_queried_object();
if ( $post ) {
$pagename = $post->post_name;
}
}
$templates = array();
if ( $template && 0 === validate_file( $template ) ) {
$templates[] = $template;
}
if ( $pagename ) {
$pagename_decoded = urldecode( $pagename );
if ( $pagename_decoded !== $pagename ) {
$templates[] = "page-{$pagename_decoded}.php";
}
$templates[] = "page-{$pagename}.php";
}
if ( $id ) {
$templates[] = "page-{$id}.php";
}
$templates[] = 'page.php';
return get_query_template( 'page', $templates );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.7.0 | The decoded form of page-{page_name}.php was added to the top of the template hierarchy when the page name contains multibyte characters. |
| 1.5.0 | Introduced. |

