Hi!
I’m trying to add a new sidebar. I only want to display this particular sidebar on a category page. Otherwise I want to show the standard sidebar.
I’ve created a new sidebar in functions.php. Like this:
register_sidebar( array(
'name' => __( 'Dog Sidebar', 'sparkling' ),
'id' => 'sidebar-2',
'description' => __( 'Extra sidebar', 'sparkling' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
This shows the sidebar area under appearance and I’m able to fill it with widgets.
I then created a category specific page called category-dogs.php and in that file i try to call my new sidebar through:
<?php get_sidebar('sidebar-2'); ?>
The problem is that my extra sidebar only appears if the standard sidebar that comes with the theme is empty and doesn’t contain any widgets.
I’ve also created a sidebar-2.php file but I’m not sure if I need it and what I need to change in this file. At the moment I have pasted the code from sidebar.php into it.
In the sidebar.php file there is the following code
<?php if ( ! dynamic_sidebar( ‘sidebar-1’ ) ) : ?>
I tried to change this to sidebar-2 in the sidebar-2.php file but because I’m not sure what is happening in this file I can’t get it to show up on the front end.