>我的页脚在正常页面中显示正常。我创建了一个新的帖子模板,并将其放在页脚中:
<?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 -->
谁能提出这是为什么?谢谢。
在您的代码中,页脚仅在"if 句子"正确时显示。 dynamic_sidebar("侧边栏-2")仅在小部件"sidebar-2"存在并且具有内容时返回true。
确保您已将内容添加到"外观>小部件"中的侧边栏 2。
此外,您应该在"if 句子"中使用"is_active_sidebar",因为dynamic_sidebar内容发送到输出缓冲区。
如果您在"侧边栏 2..."中有内容,另一种可能性是链接到该位置的某些小部件中存在错误。
放在文件的开头:
error_reporting(E_ALL);
ini_set('display_errors', 1);
并观察页面中是否显示一些错误。
您也可以从侧边栏 2 中删除所有内容,并仅尝试使用某些文本。