Home Daily Marketing Tips About Me Work With Me

Marketing & Design Blog

Internet Marketing, SEO, Blogging, Social Media, Lead Generation and Analytics

Multiple WordPress Sidebars

On this site that I have a slightly different sidebar for some of the main pages of the site as compared to the post pages. Using multiple sidebars in WordPress can be a great way to change the flow and design of your WordPress based website.

Some people use a hierarchy method in the naming of the template files to achieve this effect, but in my opinion it is too cumbersome for most user’s needs to do in that manor.

The method of multiple sidebars for WordPress that I am using on this site is a very simple PHP snippet added to the template to call the desired sidebar.php file depending on the area of the site that you are in.

I have created two sidebar files for the template and named them differently (for my example we will call the two files “sidebar_a.php” and “sidebar_b.php” to keep them separate (you may name these files anything you like).

In the standard template files, there is a small line of code that calls the sidebar content to the page. This line is typically found on the page.php file near the top; however, this may be in a different place depending on the template that you are using.

The line you are looking for looks like this:

<?php get_sidebar(); ?>

To call multiple WordPress sidebars and use a different sidebar on specific pages, you would need to change this line to the following:

<?php if (is_page(XX)) {include (‘sidebar_b.php’); }
else if (is_page(XX)) {include (‘sidebar_b.php’); }
else {include (‘sidebar_a.php’); }
?>

* You must replace the “XX” above with the ID number of the page you want the sidebar to appear on.

Using this method will call the standard sidebar_a.php file to all pages, except for the pages that are specifically instructed to call the sidebar_b.php file.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

15 Comments »

  1. Thanks for the info!

    Comment by Anfisa — November 5, 2008 @ 8:26 pm

  2. Thank you so much this made my life easier. If i was using wordpress MU will i still have to do that ?

    web design seo’s last blog post… Pay Per Click Is it Worth It ?

    Comment by web design seo — April 13, 2009 @ 9:09 am

  3. did’nt work for me.

    Warning: include(�sidebar2php�) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\themes\blue-skies\page.php on line 72

    Warning: include() [function.include]: Failed opening ‘�sidebar2php�’ for inclusion (include_path=’.;C:\xampp\php\pear\’) in C:\xampp\htdocs\wordpress\wp-content\themes\blue-skies\page.php on line 72

    I put the codes exactly alike just changing sidebar_a for sidebar1 and so..

    Comment by J.Riley — April 20, 2009 @ 12:25 pm

  4. I had the same problem as J. Riley.
    First I realised that if you cut and paste (which I did) the single commas around the ‘sidebar_b.php’ have to be corrected.
    Problem still persisted but after studying the WordPress codex on “is_page” that the ID also has to have single commas.

    Works fine now

    Comment by Tony Boyce — May 25, 2009 @ 2:42 pm

  5. You might find this useful too:
    http://blogcraving.com/sidebars-pages-wordpress-blog/

    And there’s also a fully illustrated instruction set you can get by email. Provides a little more detail if the plain text version is hard to follow.

    Travis Lusk’s last blog post… How To: Different Homepage and Single Post Sidebars

    Comment by Travis Lusk — May 28, 2009 @ 9:30 pm

  6. Your news is a cool stuff man, keep it going.

    Comment by romonoeroetoko — July 15, 2009 @ 10:47 am

  7. Hey man great post, I just CANNOT get the posts inside my category to also have the secondary sidebar that Im working on! any help please

    Comment by Carlos — July 24, 2009 @ 6:03 am

  8. My page sorry: http://revista-amauta.org/archives/category/tarro

    Comment by Carlos — July 24, 2009 @ 6:04 am

  9. I got it: All I had to do was go to single.php and place the code:

    That way I got the same sidebar on the category main page and all the specific posts inside that category, thankx for the tutorial man!

    Comment by Carlos — July 24, 2009 @ 1:55 pm

  10. great post very informative

    Comment by michael — July 30, 2009 @ 11:39 pm

  11. That’s good man, keep it going.

    Comment by amenodimeno — July 31, 2009 @ 10:52 am

  12. Stunning blog and good article. High 5 for u man !

    Comment by adamoerikom — September 19, 2009 @ 2:25 pm

  13. This is a very good stuff man. But you can be more specific next time. See ya !

    Comment by adamusxyz — January 6, 2010 @ 12:33 pm

  14. You can also do get_sidebar('example');, and WordPress will look for a file in your theme called sidebar-example.php.

    Comment by Zack Katz — February 19, 2010 @ 10:15 am

  15. Awesome Article, Really very informative posting which provide lots of informative in all the regards.thanks for the wonderful posting.

    Comment by MBT lover — February 22, 2010 @ 12:59 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

logo design brand development

We have simplified the typical logo ordering process, put you in direct contact with the artist, made getting additional branding products and websites easy, and rounded it all off with high quality printing services at fantastic rates... Learn more

website design development

We have made getting a completely dynamic website built on the WordPress content management system with a theme of your choice easy. We integrate your logo into the site design and offer great add-ons at amazing prices - giving you a range of choices on design and layout... Learn more

search engine optimization

We have expert SEO consultants ready to tackle any aspect of your search engine marketing and optimization needs. We take pride in the ability to custom build an Internet marketing campaign that is perfectly suited to your needs.... Read more


© Copyright 2003-2010 Zach Graeve and Expert Online Services, LLC. All Rights Reserved.
 Subscribe, RSS, Comments RSS, XML Sitemap, Privacy Policy