我有一个简单的问题,我希望有人能解释一下。我有一个带有自定义页面模板的子主题,我只是想检查天气是否正在使用该模板。在正常情况下,我只会使用 is_page_template
函数,但它似乎不适用于子主题。我试过以下
if(is_page_template('template-custom-fullwidth.php')){
//do something..
}
还有
if(is_page_template(dirname(get_bloginfo('stylesheet_url')).'/template-custom-fullwidth.php'){
//do something..
}
Neiter 有效,我希望有比使用 $_SERVER
检查 URL 更优雅的解决方案。我无法想象没有这种功能,因为这似乎是一项常见任务。我认为问题在于模板目录和样式表目录之间的区别。是否可以使用 Wordpress 检查位于子主题中的页面模板?
提前致谢!
最佳答案
我遇到了类似的问题。一些试验和错误注意到,如果条件保留在函数内,它就可以工作。但如果放在外面就不会。
function team_page_enqueue_style() {
if ( is_page_template('page-team.php') ) {
wp_enqueue_style( 'easy-responsive-tabs-css', get_stylesheet_directory_uri() . '/css/easy-responsive-tabs.css', array(), NULL);
}
}
add_action( 'wp_enqueue_scripts', 'team_page_enqueue_style' );
关于php - 检查子主题中的页面模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15382019/