Forums

Uniqe Sidebars change to default with single post display (5 posts)

  1. pixelrow
    Member
    Posted 1 year ago #

    I have several templates pages(- each displaying posts from one different category) also each with a unique sidebar.

    BUT when each single post is displayed, the sidebar changes to defult. I want to be able to display each post with the sidebar category, page template it belongs to.

    Any pointer are welcome. Please Help.

  2. riversatile
    Member
    Posted 1 year ago #

    You have to register each new sidebar in your function.php file. Is it done ?

  3. riversatile
    Member
    Posted 1 year ago #

    I don't think, so the system takes the default one.

    This can help you :
    This is a part of my function.php file

    /*
    #######################################
    Déclaration des sidebars et boites de Widgets WordPress
    #######################################
    */
    
    // Sidebar #1 par défaut
    if ( function_exists('register_sidebar') )
        register_sidebar();
    
    // Sidebar #2 (single.php)
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Sidebar2 - single.php',
    'before_widget' => '<div id="sidebar"><ul><li>',
    'after_widget' => '</li></ul></div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    
    // Sidebar #3 (category.php et tag.php)
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Sidebar3 - category.php et tag.php',
    'before_widget' => '<div id="sidebar"><ul><li>',
    'after_widget' => '</li></ul></div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
  4. pixelrow
    Member
    Posted 1 year ago #

    Although I do have each unique sidebar registered. BUT ... My template file has edited "Category" "recent Post" for each template file. Which are outside the dynamic widget bit. Hand coded.

    I am calling separate files like sidebar-topic, sidebar-translation etc.

  5. pixelrow
    Member
    Posted 1 year ago #

    Solved it my self:

    because the category was unique to each template so added this conditional code in the single post file.

    <?php

    if ( in_category('translations') ) :
    get_sidebar('translations');
    elseif ( is_404() ) :
    get_sidebar('404');
    else :
    get_sidebar();
    endif;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic