Creating a different side bar for single posts than for main page.

How can I create a different side bar for single posts than for main page?

At the moment I have 2 working one for pages and one for the blog

Read More

thanks

this is how it looks in funtions.php

// Register Sidebars
register_sidebar(array('name' => 'Sidebar Blog','id' => 'sidebar-blog'));
register_sidebar(array('name' => 'Sidebar Pages','id' => 'sidebar-pages'));
register_sidebar(array('name' => 'Footer','id' => 'sidebar-footer'));

// Register Menus
register_nav_menu( 'top_navi', 'Top Navigation' );
register_nav_menu( 'main_navi', 'Main Navigation' );

this is how it looks in sidebar.php

<div id="sidebar">  
    <ul>

<?php
    if(is_page() && is_active_sidebar('sidebar-pages')) : dynamic_sidebar('sidebar-pages');
    elseif(is_active_sidebar('sidebar-blog')) : dynamic_sidebar('sidebar-blog');
else : ?>

    <?php wp_list_categories('title_li=<h2>Categories</h2>'); ?>

    <?php wp_list_pages('title_li=<h2>Pages</h2>'); ?>

    <li><h2>Archives</h2>
        <ul>
        <?php wp_get_archives(); ?>
        </ul>
    </li>

    <?php wp_list_bookmarks(); ?>

<?php endif; ?>

    </ul>
</div>

Thanks !

Related posts

Leave a Reply

2 comments

  1. I would consider the following …

    Register a new sidebar:

    function your_new_widget() {
    register_sidebar( array(
        'name'          => __( 'Single View Sidebar', 'your_textdomain' ),
        'id'            => 'sidebar-single',
        'description'   => __( 'This widget area is found only on the single post view.', 'your_textdomain' ),
    ) );
    }
    add_action( 'widgets_init', 'your_new_widget' );
    

    Create a new sidebar template:

    /** New file: sidebar-single.php */
    if ( is_active_sidebar( 'sidebar-single' ) ) :
        dynamic_sidebar( 'sidebar-single' );
    endif;
    

    Then modify your ‘single.php’ template to call the new sidebar (above):

    /** Modify single.php */
    get_sidebar( 'single' );
    

    Of course you will need to flesh out the new single view sidebar template file … and the WordPress Template Hierarchy will take care of using your new sidebar on single post views.

  2. Register the sidebars:

    register_sidebar(array('name' => 'Sidebar Blog','id' => 'sidebar-blog'));
    register_sidebar(array('name' => 'Sidebar Pages','id' => 'sidebar-pages'));
    register_sidebar(array('name' => 'Sidebar Post','id' => 'sidebar-posts'));
    

    Then, in your sidebar template, use the is_page() and is_single() conditional tags:

    if( is_page() && is_active_sidebar('sidebar-pages') ){
         dynamic_sidebar('sidebar-pages');
    
    }elseif( is_single() && is_active_sidebar('sidebar-posts') ){
         dynamic_sidebar('sidebar-posts');
    
    }elseif( is_active_sidebar('sidebar-blog') ){
         dynamic_sidebar('sidebar-blog');
    
    }else{
        //Default
    }