1
votes

Problem: A third sidebar I've added is not appearing on the target page.

Description: I wanted to see if anyone can see anything I'm missing in the steps to create and display a widget sidebar in a particular template. Using the situation described below the sidebar appears on the widgets admin page but when the template renders the sidebar is the default sidebar, which suggests that the dynamic sidebar is not being found by the template. This is the second sidebar I've added. if I replace the sidebar name in the template tag with the name of the first additional template the page renders with the first customized sidebar.

Steps to create additional widget sidebars and display them with selected templates

1) Register the sidebar in the child theme in functions.php
2) In the registration process assign a name and ID to the new sidebar
3) Create an additional sidebar template based on the existing template. Copy the existing template and change the name of the dynamic template to match the newly registered sidebar
4) Go to the template where you want the sidebar to display and insert the name of the sidebar into the get_sidebar() template tag.
5) Go to the admin panel and drag widgets onto the new sidebar book post

Specifically this might look like:

  1. Register the sidebar:

    if ( function_exists ('register_sidebar'))
        register_sidebar( array(
        'name'          => __('bookpost'),
        'id'            => 'sidebar-bookpost',
        'description'   => 'Sidebar for showing ad and section list on the template single-book.php',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>' ));
    
  2. Assign name bookpost and sidebar-bookpost
  3. Create an additional sidebar template named sidebar-bookpost.php. Edit the line

    So that it now reads

    get_sidebar('bookpost');
    

and finally use the widgets admin page to assign widget.

1

1 Answers

3
votes

Are you trying to get dynamic sidebar?? if so then use

<?php if ( is_active_sidebar( 'sidebar-bookpost' ) ) : ?>

        <?php dynamic_sidebar( 'sidebar-bookpost' ); ?>

<?php endif; ?>

instead of get_sidebar('bookpost');

.........