WordPress.org

Ready to get started?Download WordPress

Forums

Adding Widget Sidebar for specific template (1 post)

  1. dorich
    Member
    Posted 1 year ago #

    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

    <?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>

    So that it now reads
    <?php if ( ! dynamic_sidebar( 'sidebar-bookpost' ) ) : ?>
    4. Go to the template tag and change
    get_sidebar();
    To
    get_sidebar('bookpost');

    Finally go to widgets page and assign widgets.

    Thanks for any thoughts on what might be wrong with the process.

Topic Closed

This topic has been closed to new replies.

About this Topic