WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. minute44
    Member
    Posted 6 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.

    Thanks.

  2. minute44
    Member
    Posted 6 years ago #

    Bump!

    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
    Member
    Posted 6 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
    Member
    Posted 6 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
    Member
    Posted 6 years ago #

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

  6. Jeremy Clark
    Moderator
    Posted 6 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
    Member
    Posted 6 years ago #

    There may be some more hints elsewhere on the forum.

  8. Gestroud
    Member
    Posted 6 years ago #

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

  9. minute44
    Member
    Posted 6 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
    Member
    Posted 6 years ago #

    bump

  11. canvasd
    Member
    Posted 6 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