Hello all I would like to add multiple sidebars to my wordpress site I currently have 2 sidebars registered in functions.php like so:
function themename_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'themename' ),
'id' => 'sidebar-1',
'description' => 'Sidebar for all pages',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Sidebartwo', 'themename' ),
'id' => 'sidebar-2',
'description' => 'Sidebar for product page',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'themename_widgets_init' );
in my sidebar.php I currently have this code which will add default data to my sidebars incase I have not added any widgets.
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h1 class="widget-title"><?php _e( 'Archives', 'themename' ); ?></h1>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h1 class="widget-title"><?php _e( 'Meta', 'themename' ); ?></h1>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary -->
Would anyone know how to go about doing the same for my sidebar-2 from what I have read i must create a sidebar-2.php which I have done and included the same code as above like so:
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h1 class="widget-title"><?php _e( 'Archives', 'themename' ); ?></h1>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h1 class="widget-title"><?php _e( 'Meta', 'themename' ); ?></h1>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary -->
But unfortunately it is not working does anyone know why?
get_sidebar()
?<?php get_sidebar('sidebar-2'); ?>
the sidebar-1 still shows in its place.sidebar-2.php
then the correct use isget_sidebar( '2' );
<?php get_sidebar('ID'); ?>
but its already registered and waiting to be called with a sidebar template page of course thank you very much again