Adding two sidebars in wordpress child theme

2019-04-16 02:15发布

In Wordpress I want to make two sidebars. One will be in left hand side of the content and the other one will be in the right hand side (default sidebar) in twentyelven theme. For that I made little bit customization to my twentyeleven child theme. In functions.php I made this changes

 register_sidebar( array(
    'name' => __( 'Left Hand Sidebar', 'buygames' ),
    'id' => 'sidebar-left',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => "</aside>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
  ) );

Then in sidebar-page.php I added this code

 <div id="left-sidebar">
  <?php dynamic_sidebar( 'sidebar-left' ); ?>
  </div><!--#left-sidebar-->

just after the code get_header(); and before the <div id="primary">....</div>. This is working fine but I think this is the wrong method. By doing this it will be hard-coded. So can some one suggest me what will be the good way to do this without making any hard coding? Any help and suggestions will be highly appreciable.

1条回答
何必那么认真
2楼-- · 2019-04-16 02:42

You can add both sidebars to the sidebar.php of your childtheme and arrange them per css.

// your sidebar
<div id="left-sidebar">
  <?php dynamic_sidebar( 'sidebar-left' ); ?>
</div><!--#left-sidebar-->
// original sidebar
<div id="sidebar">
  <?php dynamic_sidebar( 'sidebar' ); ?>
</div><!--#sidebar-->

Be sure to add both sidebars because the sidebar.php of your child theme overwrites the original one.

查看更多
登录 后发表回答