确定当前是否在页面模板中。
原型
is_page_template( string|array $template = '' )
描述
此模板标记允许你确定你是否在页面模板中。你可以选择提供模板名称或模板名称数组,然后检查将特定于该模板。
参数
$template
(string|array)
(Optional)
要匹配的特定模板名称或模板数组。
返回值
(bool)
成功时是真的,失败时是假的。
源文件
路径:wp-includes/post-template.php
<?php
...
function is_page_template( $template = '' ) {
if ( ! is_singular() ) {
return false;
}
$page_template = get_page_template_slug( get_queried_object_id() );
if ( empty( $template ) )
return (bool) $page_template;
if ( $template == $page_template )
return true;
if ( is_array( $template ) ) {
if ( ( in_array( 'default', $template, true ) && ! $page_template )
|| in_array( $page_template, $template, true )
) {
return true;
}
}
return ( 'default' === $template && ! $page_template );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/is_page_template/