is_page_template
函数
is_page_template ( $template = '' )
- 参数
-
-
(string|string[])
$template
The specific template filename or array of templates to match.- Required: 否
- Default: (empty)
-
(string|string[])
- 返回值
-
- (bool) True on success, false on failure.
- 定义位置
-
-
wp-includes/post-template.php
, line 1786
-
wp-includes/post-template.php
- 引入
- 2.5.0
- 弃用
- –
Determines whether the current post uses a page template.
This template tag allows you to determine if you are in a page template.
You can optionally provide a template filename or array of template filenames
and then the check will be specific to that template.
For more information on this and similar theme functions, check out
the {@link Conditional Tags} article in the Theme Developer Handbook.
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 );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。