我的页脚在正常页面中显示得很好。我创建了一个新的帖子模板,并在页脚中添加了以下内容:
<?php if ( !function_exists('dynamic_sidebar') || dynamic_sidebar('sidebar-2'))
get_footer();就像这样,我的小部件显示得很好。在我的函数文件中,我有以下内容:
add_action( 'widgets_init', 'child_register_sidebar' );
function child_register_sidebar(){ register_sidebar(array(
'name' => 'Sidebar 2 for single_withnotes',
'id' => 'sidebar-2',
'description' => '',
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<span class="widget-title">',
'after_title' => '</span>',
));
}我的新侧边栏看起来像这样:
if ( ! is_active_sidebar( 'sidebar-2' ) ) {
return;
}
?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-2' ); ?>
</div><!-- #secondary -->有没有人能告诉我为什么会这样?谢谢。
发布于 2016-07-17 17:37:18
在您的代码中,您的页脚仅在"if语句“正确时显示。Dynamic_sidebar(“侧边栏-2”)仅当小部件“侧边栏-2”存在并且有内容时才返回true。
确保您已经在Appearance>小部件的侧边栏中添加了内容。
此外,您还应该在"if语句“中使用"is_active_sidebar”,因为dynamic_sidebar会将内容发送到输出缓冲区。
如果您在"Sidebar 2...“中有内容,另一种可能是链接到该位置的某些小工具中存在错误。
放在文件的开头:
error_reporting(E_ALL);
ini_set('display_errors', 1);并观察页面中是否显示了一些错误。
此外,您还可以删除边栏2中的所有内容,只尝试一些文本。
https://stackoverflow.com/questions/38419725
复制相似问题