如何在2111儿童主题中创建自己的侧边栏?

时间:2012-03-10 作者:Borek Bernard

当我在2111主题中配置小部件时,有5个“侧栏”:

主侧边栏在子主题中,我想在帖子上支持侧边栏,这很容易使用these instructions 但同时,主页上的主侧边栏应该与单个页面上的侧边栏不同。

我是否可以创建一个新的“侧边栏区域”,以便将小部件拖放到管理部分?或者我应该使用页脚区域的第三列(我在博客中没有使用)来支持这一点吗?我会替换它们吗get_sidebar() 在修改后的single.php 文件

1 个回复
最合适的回答,由SO网友:Jeremy Jared 整理而成

我想我知道我在找什么。我把从我的主题部分中提取的一些代码放在一起,给你一个例子。

For the functions.php:

<?php
add_action( \'after_setup_theme\', \'ideatree_init\' );
if ( ! function_exists( \'ideatree_init\' ) ):
function ideatree_init() {
// REGISTER THE NAV MENUS (3 in this case)
add_action( \'init\', \'register_my_menus\' );
function register_my_menus() {
register_nav_menus(
    array(
        \'main\' => \'main\' ,
        \'secondary\' => \'secondary\',
        \'tertiary\' => \'tertiary\'
        )
    );
}
// REGISTER THE SIDBARS
if ( !function_exists(\'ideatree_widgets_init\') ) {
function ideatree_widgets_init() {
    register_sidebar( array(
        \'name\' => __( \'main-widget\', \'ideatree\'),
        \'id\' => \'main-widget\',
        \'description\' => \'The Main widget\', \'ideatree\' ,
        \'before_widget\' => \'<ul><li id="%1$s" class="widget-container %2$s">\',
        \'after_widget\' => \'</li></ul>\',
        \'before_title\' => \'<h3 class="widgettitle">\',
        \'after_title\' => \'</h3>\',
    ) );
    register_sidebar( array(
        \'name\' => \'showcase-widget\', \'ideatree\',
        \'id\' => \'showcase-widget\',
        \'description\' => \'The showcase-widget\', \'ideatree\' ,
        \'before_widget\' => \'<ul><li id="%1$s" class="widget-container %2$s">\',
        \'after_widget\' => \'</li></ul>\',
        \'before_title\' => \'<h3 class="widgettitle">\',
        \'after_title\' => \'</h3>\',
    ) );
    register_sidebar( array(
        \'name\' => \'First Footer Widget\', \'ideatree\',
        \'id\' => \'first-footer-widget\',
        \'description\' => \'The first footer widget\', \'ideatree\' ,
        \'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
        \'after_widget\' => \'</li>\',
        \'before_title\' => \'<h3 class="widgettitle">\',
        \'after_title\' => \'</h3>\',
    ) );
    register_sidebar( array(
        \'name\' => \'Second Footer Widget\', \'ideatree\',
        \'id\' => \'second-footer-widget\',
        \'description\' => \'The second footer widget\', \'ideatree\',
        \'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
        \'after_widget\' => \'</li>\',
        \'before_title\' => \'<span class="widgettitle">\',
        \'after_title\' => \'</span>\',
    ) );
    register_sidebar( array(
        \'name\' => \'Third Footer Widget\', \'ideatree\',
        \'id\' => \'third-footer-widget\',
        \'description\' => \'The third footer widget\', \'ideatree\',
        \'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
        \'after_widget\' => \'</li>\',
        \'before_title\' => \'<h3 class="widgettitle">\',
        \'after_title\' => \'</h3>\',
    ) );
}
add_action( \'widgets_init\', \'ideatree_widgets_init\' );
}
//===============\\\\ VARIOUS WP THEME SUPPORTS //===================
    if ( ! isset( $content_width ) ) $content_width = 600;
      add_theme_support( \'post-thumbnails\' );
      add_image_size( \'bigmutha\',580, 180, true ); //Can be used for Portfolio etc...
      add_theme_support(\'automatic-feed-links\');
  }
endif;
?> 

For the sidebar.php:

<div id="sidebar">

  <?php /** Home Page Sidebar */
    if ( is_page(\'Home\') ) { 
    ?>  
      <div id="main-sidebar">
        <?php if ( ! dynamic_sidebar( \'main-widget\' ) ) : 
          endif; ?>
      </div>

  <?php /** showcase page sidebar */ }
    if ( is_page(\'showcase\') ) { 
    ?>
    <div id="showcase-sidebar">
        <?php if ( ! dynamic_sidebar( \'showcase-widget\' ) ) : 
          endif; ?>
    </div>
  <?php } ?>

</div>

The footer.php file:

<div id="footer">
  <div class="left-footer">
    <?php if ( function_exists ( dynamic_sidebar(3) ) ) : ?>
        <?php dynamic_sidebar (3); ?>
    <?php endif; ?>
  </div>
  <div class="middle-footer">
    <?php if ( function_exists ( dynamic_sidebar(4) ) ) : ?>
        <?php dynamic_sidebar (4); ?>
    <?php endif; ?>
  </div>
  <div class="right-footer">
    <?php if ( function_exists ( dynamic_sidebar(5) ) ) : ?>
        <?php dynamic_sidebar (5); ?>
    <?php endif; ?>
  </div>
</div><!-- End Footer -->
<?php wp_footer(); ?>
</body>
</html>
您应该首先在测试服务器上进行测试。正如我提到的,这是从两个不同的主题中提取出来的,没有一起测试过。不过这对你应该有用。如果你有任何问题,请告诉我。

结束

相关推荐

Give Editor Access To Sidebar

我想让编辑器角色有权编辑提要栏及其内容。我有一个文本小部件在那里,为了编辑这个文本小部件,用户需要是管理员-这太糟糕了。如何授予编辑器角色权限,使其能够编辑侧边栏?