Making each page display a different sidebar. (11 posts)

  1. minute44
    Posted 8 years ago #

    Quick question:

    Roughly, how would I go about making each page display a bespoke sidebar? Would I need to edit my sidebar.php and add in some if, then, else tom foolery to make it look what the current page is then display accordingly?

    I'm not in any great hurry, I may just want to do this in the future.


  2. minute44
    Posted 8 years ago #


    I was thinking along these lines... I could have say 3 different sidebar files: sidebar.php, sidebar2.php and sidebar3.php

    How would I get say archive.php to pull sidebar2.php and a singe post pull sidebar3.php ??

    Is this the way i should approach this?

  3. Roy
    Posted 8 years ago #

    That doesn't sound too hard. Look in your index.php, archive.php and single.php. On the bottom it says "get sidebar". I don't know if it's as easy as to make it into "get sidebar1", but I guess you'll let us know when you find out.

    [edit] :
    I took a quick look at my theme and the command is actually <?php get_sidebar(); ?>. I think what I said above was a bit too easily thought, but I still think that making <?php get_sidebar1(); ?> would be worth the try.

  4. minute44
    Posted 8 years ago #

    ah well, I thought that too but it doesn't just call the file it uses a function called get_sitebar. I'm worried i'd need to create seperate functions for the different sidebar PHP files.

  5. Roy
    Posted 8 years ago #

    Ok, in that case a more expert user better respond...
    (and I was editing while you responded btw.).

  6. Jeremy Clark

    Posted 8 years ago #

    You could do this with conditional tags, and a single sidebar file. For example

    <? php if (is_archive()){ ?>
    Custom code
    <? php elseif (is_page()) { ?>
    Other code
    <? php } ?>

    Just a quick example your code might be different.

  7. Roy
    Posted 8 years ago #

    There may be some more hints elsewhere on the forum.

  8. Gestroud
    Posted 8 years ago #

    I haven't tried it yet, but you could try the WP Widget Changer plugin.

  9. minute44
    Posted 8 years ago #

    Ok, got it working roughly with this:

    <?php if (is_home()) {
    include (TEMPLATEPATH . "/sidebarmain.php");
    } else {
    include (TEMPLATEPATH . "/sidebargalleries.php");

    Now the next step. How would I edit that code so that all pages show sidebarmain.php except my galleries page or any of it's children?

  10. minute44
    Posted 8 years ago #


  11. canvasd
    Posted 7 years ago #

    re-bump -- anyone want to code a sidebar switcher plugin that would let you choose sidebars in the Admin>write area? Simple, necessary thing!

Topic Closed

This topic has been closed to new replies.

About this Topic