
cPanel服务器管理面板概述
is_page_template ( $template = '' )
is_page_template: 这个函数检查当前页面是否使用了一个特定的页面模板。它将模板名称作为参数,如果页面使用该模板,则返回true,如果不使用则返回false。
确定当前的文章是否使用了一个页面模板。
这个模板标签允许你确定你是否在一个页面模板中。你可以选择提供一个模板文件名或模板文件名的数组,然后检查将特定于该模板。
关于这个和类似主题功能的更多信息,请查看《主题开发者手册》中的{@link Conditional Tags}文章。
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 ); }