solostream

Showing different sidebar on different pages

| February 21, 2007 | 8 Comments

To show a different sidebar on different pages, replace the standard call for the sidebar:

<?php get_sidebar(); ?>

with the following code:

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

The same can be done to call different headers, i.e. instead of <?php get_header(); ?> use <?php include ('header2.php'); ?>For more information, see Different Sidebars Anyone? on the WordPress codex.

Tags: ,

Category: Code Snippets, Tips

Elegant WP Themes

Comments (8)

Trackback URL | Comments RSS Feed

  1. Tony says:

    But wait, which page do I add/change this code on?!

  2. joanne says:

    thanks for this tips! was really useful as i was configuring a website for my client :)

  3. junthit says:

    What next? confuse……….

  4. For the ones who are confused:
    1. You create a new page template (check google)
    2. In your new page template php, you do these changes mentioned here.
    3. Select your new template on the pages you want to have your new sidebar :)
    I think that should answer you :)

  5. cole says:

    The only problem with this, it’s kinda crazy to create a different template for every sidebar. I did it this way for a while and wound up with a dozen or so extra files in my WP theme folder. It sucked. Better to use some if/then magic in your sidebar or page.php

  6. Weptile says:

    @cole, well yo uare right cole but if yo do that, that means you basically are adding load time to the site. Shorter the files to load is better.
    But on the other hand, not every site is harmed by few lines of code you might add to a file. It depends if it’s worth it :)
    Do you have some example of this “magic” you are talking about? :)

  7. HelloNingbo says:

    Nice and interesting topic!
    I wished we could have developed the subject a bit more…

  8. Rizwan says:

    Thank you ! I was looking for this

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.