我创建了一个自定义主题和一个非常基本的布局我的WordPress(4.7)应用程序,它看起来是这样的:我怎样才能把多个侧边栏在我的模板的不同区域中的WordPress
在我functions.php
文件我已经注册了几个sidebars
。
function flowershouse_widgets_init(){
register_sidebar(array(
'name' => __('Main content left', 'flowershouse'),
'id' => 'content-main-left',
'description' => __('Add widgets to appear in left column of main content area', 'flowershouse'),
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Main content right', 'flowershouse'),
'id' => 'content-main-right',
'description' => __('Add widgets to appear in right column of main content area', 'flowershouse'),
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Sidebar', 'flowershouse'),
'id' => 'sidebar-1',
'description' => __('Add widgets here to appear in sidebar', 'flowershouse'),
'before_widget' => '<section id="%1$s" class="%2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Footer Left', 'flowershouse'),
'id' => 'footer-left',
'description' => __('Add widgets to appear in left footer', 'flowershouse'),
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Footer Middle', 'flowershouse'),
'id' => 'footer-middle',
'description' => __('Add widgets here to appear in middle footer column', 'flowershouse'),
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Footer Right', 'flowershouse'),
'id' => 'footer_right',
'description' => __('Add widgets here to appear in Right footer column', 'flowershouse'),
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_widget' => '<h2>'
));
}
add_action('widgets_init', 'flowershouse_widgets_init');
所有注册的侧边栏下Appearance > Widgets
页面可用。在sidebar.php
文件我有这样的:
if (is_active_sidebar('sidebar-1')) {
dynamic_sidebar('sidebar-1');
}
if (is_active_sidebar('content-main-left')){
dynamic_sidebar('content-main-left');
}
我把搜索小工具下sidebar-1
并把Meta
下content-main-left
侧边栏。但是,当页面呈现这两个小部件都显示在同一个侧栏下。这是我index.php
看起来像:
...
<div class="row margin-t20">
<div class="col-md-9 col-sm-9 col-xs-12">
<div class="box box-gray padd-10-all">
Left column with 9 column
<div class="row margin-t10">
<div class="col-md-3 col-sm-3 col-xs-12">
<div class="box box-white padd-10-all">
<!-- Here I want 'content-main-left' sidebar widgets to render -->
<?php get_sidebar('content-main-left'); ?>
</div>
</div>
<div class="col-md-9 col-sm-9 col-xs-12 mobile-v-space">
<div class="box box-white padd-10-all">
Right content<br />(inside 9-column left column)
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 mobile-v-space">
<div class="box box-white padd-10-all">
<!-- Here I want 'sidebar-1' sidebar widgets to render -->
<?php get_sidebar('sidebar-1'); ?>
</div>
</div>
<div class="clearfix"></div>
</div>
...
我做错了吗?
评论不适用于扩展讨论;这次谈话一直[移动聊天](http://chat.stackoverflow.com/rooms/130830/discussion-on-question-by-subrata-sarkar-how-can-i-put-multiple-sidebars-in-差异)。 –