答案在这里找到:是_活动的_侧栏()总是返回False
按用户:s_ha_dum
我动态地创建侧边栏,并为每个顶级页面注册它们:
问题是,我想测试该页面是否不存在侧边栏,以便使用默认值:
if(is_dynamic_sidebar(get_the_title()))
dynamic_sidebar(get_the_title());
else
dynamic_sidebar('Default');我试过测试
if(is_dynamic_sidebar(get_the_title()) && dynamic_sidebar(get_the_title()),但由于某种原因,这只会重复侧边栏内容两次。我也试过:
if(is_dynamic_sidebar(get_the_title()) && is_active_sidebar(get_the_title()),但这只是删除了我的所有侧边栏,或者如果我将&&更改为||,它将正常显示,除非使用默认。因此,在我的子页面上,它几乎没有使用侧栏。有人对我能做什么有什么建议吗?
感谢@Ravs更新代码
if(!is_active_sidebar(get_the_title()))
dynamic_sidebar(get_the_title());
else
dynamic_sidebar('Default');发布于 2013-07-27 16:29:31
由于父页上有特定的侧栏,子页上有默认的侧栏,所以您的条件可能是(我假设您在wordpress循环中)。
如果找到并调用了
dynamic_sidebar小部件侧栏,则返回True。如果找不到或没有调用,则为False。
if($post->post_parent == 0 ){ // if page is a parent page
if(dynamic_sidebar(get_the_title()) && is_active_sidebar(get_the_title()))
dynamic_sidebar(get_the_title());
else
dynamic_sidebar('Default');
}
else{ // if page is a sub page
dynamic_sidebar('Default');
}https://wordpress.stackexchange.com/questions/107843
复制相似问题