sidebar in wordpress

I want to display different dynamic sidebar on different pages, how do I access multiple sidebar on my pages.

Related posts

Leave a Reply

4 comments

  1. You should create files like sidebar-xxxx.php and include it, using get_sidebar(xxxx) in the different templates and souhld register them on the functions.php. If you do not wanna create these files you can register the sidebars on functions.php and in the sidebar.php use:

    global $wp_query;
    $page_name = $wp_query->post->post_name;
    <ul>
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-'.$page_name) ) : ?>
    <?php endif; ?>
    </ul>
    
  2. create a new sidebar

    and you can link them inc with is page

    if(is_page(5)) {
     include('new-sidebar.php')
    }
    

    is page id is 5 lets say thats the id for your home page

    just check the ids of your pages and seperate them

    if you want them tho show in the page childs to

    just write

     if(is_page(5) || $post->post_parent) {
         include('new-sidebar.php')
        }
    

    zou can even write a function either

  3. For different sidebars, i thing you have to do is to create the sidebar which you want as many as you want and save those sidebars as sidebar1.php, sidebar2.php and so on.

    And,just include it in the different pages where you want it to display like this:

    <?php include('sidebar1.php'); ?> 
    

    And, like wise for other sidebars of other pages.