I have a custom post type called “bibliographies” and the corresponding archive-bibliographies.php file to show a list of posts. On this page I want to add a side bar that is unique to this page, so I went ahead and registered a new sidebar like this:

// Register Bibliography Sidebar
function bibliography_sidebar() {
    register_sidebar( array(
        'name' => 'bibliography_sidebar',
        'id' => 'bibliography_sidebar',
        'description' => __( 'Widgets in this area will be shown on the bibliography sidebar.', 'theme-slug' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2 class="bibliography_sidebar">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'bibliography_sidebar' );

then on the archive-bibliopgraphies.php file I’m trying to call the sidebar like this:

get_sidebar('bibliography_sidebar');

I see the new side bar on the admin side and I’m able to add widgets to it, but on the front end all I get is the main side bar, not the “bibliography_sidebar” sidebar.

Any ideas what I’m missing here?

1 Answer
1

get_sidebar($name) will load a template sidebar-{$name}.php. If sidebar-{$name}.php does not exist, then it will fallback to loading sidebar.php.

to have your specific sidebar, you can create a file sidebar-bibliography_sidebar.php in your theme with this code :

<?php

if ( is_active_sidebar( 'bibliography_sidebar' ) ) {
    dynamic_sidebar( 'bibliography_sidebar' );
}

Leave a Reply

Your email address will not be published. Required fields are marked *