4

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?

2

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' );
}
| improve this answer | |
  • Thanks! Now I understand how side bars work a little better :) – Guillermo Carone Aug 28 '15 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.