I realized that I didn’t clarify how to do this very well. Sorry. Anyhoo… For single pages, you’ll want to use the following but change the name for each sidebar page you want to be different. So if you have different sidebar content for you about page and your portfolio page this is how it would look:
1 2 | <?php if (is_page(about)) { ?> <?php if (is_page(portfolio)) { ?> |
I learned today how to use one sidebar page for multiple pages with different sidebar content for each page. It may come easy to most of you but for me it was a great revelation. It’s fairly simple to do and why I hadn’t learned it before now is beyond me. I guess some days things just click.
Anyway, if you use Wordpress as a CMS (which I encourage anyone to do) these are the steps for having multiple sidebar content in one sidebar page (sidebar.php).
This method is only for using a static homepage and a static blog page
1 2 3 | <?php if (is_home()) { ?> // CONTENT GOES HERE <?php } ?> |
To get the code to work for you, change the word “about” to fit the name of the page you’re trying to add variable content to.
1 2 3 | <?php if (is_page(about)) { ?> // CONTENT GOES HERE <?php } ?> |
It’s that simple and the content you want for each individual page shows up only on that page. I can’t believe I’ve been missing out on this all this time.
14 People Have Bloviated
David Airey :: Graphic Designer | Jul 23
Hi Jen,
Hope all’s well with you lately. I didn’t know this simple piece of code either, but no doubt it’ll come in useful. Thanks for writing about it!
Pop Stalin | Jul 23
David- All is well. It’s one of those pieces of code that make you smack your head when you find it.
David Airey :: Graphic Designer » Creative resources 26 July 2007 | Jul 26
[...] Jen at Pop Stalin teaches us the code to create different sidebar content on various pages of your WordPress blog. If you use Wordpress as a CMS (which I encourage anyone to do) these are the steps for having multiple sidebar content in one sidebar page (sidebar.php). [...]
Fred | Jul 26
I used Wordpress a while ago, but found it very confusing and not that easy to configure. I’ll try again later…
beth | Aug 6
This will be a nice way to consolidate my sidebar files, thanks!
Jeff | Aug 26
Thanks for this. I recently added the top commentators plugin and want to display it only on the homepage but can’t seem to get this to work. I added it just as you have it.
Is there something else that needs to be added inside the sidebar file that makes this work?
Does this have to be there:
jameswillisisthebest | Sep 8
This is my first post
just saying HI
mike | Oct 13
hi i tried this but it it didn’t work as planned. can you show me how that code works in the context of the rest of your sidebar? thanks!
Pop Stalin | Oct 25
Mike-
I’m not real sure what you’re asking (sorry it took so long to reply) but below is sort of a working example. I don’t want to include all the content that I used for my client so I hope this makes sense to you.
One thing you need to make sure of is that there are no spaces in the final code.
< ! -- SIDEBAR ABOUT PAGE -- >< ?php if (is_page(about)) { ?>< h2 >Some Title< /h2 >< p >Some text< /p >< ?php } ?>< ! -- SIDEBAR BLOG -- >< ?php if (is_home()) { ?>< p >Some intro text< /p >< br / >< ?php include (TEMPLATEPATH . '/searchform.php'); ?>< ! -- BLOG ROLL -- >< ul >< ?php wp_list_bookmarks('categorize=1&category=2&before=<li>&after=&show_images=0&show_description=0&orderby=name'); ?>< /ul >< ?php } ?>Large balloon guy | Mar 16
I am looking for a plugin that allows you to write content for the sidebar on that specific page. know any?
Jen | Mar 17
I don’t know of any specifically designed to do that. If it were something that I’d need for a site I was designing I’d probably look into using custom fields.
dirtyharris | Jul 29
how about i want my sidebars to change contents every time i visit a category– the sidebar will contain all the posts from the category that i selected? any idea?
Jen | Jul 30
@dirtyharris:
Yes, you would use Conditional Tags. Check out this link:
http://codex.wordpress.org/Conditional_Tags
then scroll down to the section “Variable Sidebar Content.”
zacheos | Sep 9
Some people use a hierarchy method in the naming of the template files to achieve multiple WordPress sidebars, but in my opinion it is too cumbersome for most user’s needs. The method of multiple sidebars for WordPress that I use involves only a very simple PHP snippet added to the template to call the desired sidebar file depending on the area of the site that you are in.