获取给定帖子的特定模板名称。
原型
get_page_template_slug( int|WP_Post $post = null )
参数
$post
(int|WP_Post)
(Optional)
发布ID或WP_Post对象。默认为全球$ post。
返回值
(string|false)
页面模板文件名。使用默认页面模板时返回空字符串。如果帖子不存在,则返回false。
源文件
路径:wp-includes/post-template.php
<?php
...
function get_page_template_slug( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ! $template || 'default' == $template ) {
return '';
}
return $template;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_page_template_slug/