php - 检查子主题中的页面模板

标签 php wordpress templates parent-child

我有一个简单的问题,我希望有人能解释一下。我有一个带有自定义页面模板的子主题,我只是想检查天气是否正在使用该模板。在正常情况下,我只会使用 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/

相关文章:

PHP , htaccess : apply page title in URL

php - 带有 Nginx 后端的 Moodle 2.0

php - 为特定子域设置 session cookie

php - 在 Sonata-Admin 全局搜索中搜索哪些列

html - WordPress URL 中的  (OBJ) 符号?

wordpress - 新的供稿项目未显示在 Google 阅读器中

templates - 如何通过 Tridion Razor 模板中的富文本字段的组件链接插入片段

c++ - 创建模板函数的每个实例时,模板函数 typedef 说明符是否会被正确内联?

html - 当窗口调整大小时,我的导航菜单消失了

javascript - ES6 模板文字是否比字符串连接更快?