我有一个简单的问题,我希望有人能给我一些启发。我有一个带有自定义页面模板的子主题,我只是想检查天气是否正在使用该模板。在正常情况下,我只会使用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检查子主题中的页面模板?
提前感谢!
发布于 2013-03-30 03:07:05
参考此WP Codex页面:http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri
请改用get_stylesheet_directory_uri。这应该是可行的:
is_page_template(get_stylesheet_directory_uri() . '/template-custom-fullwidth.php')
{
//do something..
}发布于 2014-04-12 11:37:04
我也遇到过类似的问题。一次试错发现,如果条件保持在函数内部,它就能正常工作。但如果把它放在外面,它就不会。
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' );发布于 2013-03-30 04:05:26
如果在循环中使用了is_page_template,请尝试将wp_reset_query()放在调用is_page_template之前。
https://stackoverflow.com/questions/15382019
复制相似问题