我在主页侧边栏中添加了一些小部件,但它们没有出现在主页上。如果我在主边栏中添加一些小部件,它将出现在主页和其他页面中。
我是Wordpress的新手,我不知道如何解决这个问题,而且默认的小部件也不会出现。我正在使用wp-bootstrap
主题和问答付费插件。
首先在function.php 中注册您的主页侧边栏
function Name_widgets_init() {
register_sidebar(array(
'name' => __( 'homepage sidebar', 'test theme' ),
'id' => 'sidebar_homepage',
'description' => __( 'This Wwill appear on homepage sidebar', 'test theme' )
) );
}
add_action( 'widgets_init', 'Name_widgets_init' );
然后使用这个技巧来显示你的小部件,把下面的代码放在你想添加侧边栏的主页上
<div class="sidebar_home" id="sidebar_left">
<?php if ( is_active_sidebar( 'sidebar-left' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar_homepage' ); ?>
</div>
<?php endif; ?>
</div>
最后注意我在最后一段代码中使用了div,请编写自己的CSS来控制它。