elegant themes

Showing different sidebar on different pages

| February 21, 2007 | 11 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.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Tags: ,

Category: Code Snippets, Tips

Elegant WP Themes

Comments (11)

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

  9. lily says:

    Can someone help me?  This didn’t work for me.  I want to have a custom sidebar for my about page, and I created a new php file for the about page as well as a new unique php for the sidebar (sidebar2.php)….  but it’s not changing, the main sidebar is still showing up.
    help please!

  10. Weptile says:

    @lily: did you change the page template from the admin panel? Your new about page should be a new template. Here are steps:
    1. Create a new page template (something like about-page.php and check google on how to)
    2. Create new sidebar php for that page (as explained above)
    3. Go to admin and edit the about page and change page template to be your new about-page template.
    That should do it. If not, you might be missing something in these steps.

  11. Mike says:

    For a codeless approach, you might try my <a href=http://www.mlynn.org/graceful-sidebar-plugin>Graceful Sidebar Plugin</a>.  This plugin enables you to customize the content of your sidebar for each page or post.  Simply create two custom fields in your page or post called “graceful_title” and “graceful_content” and drag the widget to your theme’s sidebar.
     
    Enjoy!

Leave a Reply




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

More in Code Snippets, Tips (109 of 110 articles)