Quick Tip 20 – Multiple WP Sidebars

Following a recent design issue on a site we built in Wordpress, we wanted to include several different sidebars depending on the page you were on, unfortunately trying to get this work was a little bit of an issue. However thanks to the code below we are now go.

By replacing this code with any mention of get sidebar in your theme you can specify your own sidebar dependent on the page you are on. See Below:

Quick Tip Gary

if(is_page()) {
// We're on a "page", which?
if (is_page('about')) {
// Ah, the about page!
get_sidebar('about'); // includes sidebar-about.php
} elseif (is_page('services')) {
get_sidebar('services'); // includes sidebar-services.php
} elseif (is_page('contact')) {
get_sidebar('contact'); // includes sidebar-contact.php
} else {
// if we're not any of the above pages
get_sidebar(); // includes regular sidebar.php
}
?>

So if you create a template file called sidebar-about.php and then name the template ‘about’


/*
Template Name: about
*/
?>

it will then pull in the information. Great, isn’t it!

Related posts:

  1. Quick Tip 15 – WP More Tag
  2. Quick Tip 12 – WP Gravatar
  3. Quick Tip 13 – WP Promotion
  4. Quick Tip 14 – WP E-commerce
  5. Quick Tip 19 – WP Permalinks

Tags: , ,

One Response to “Quick Tip 20 – Multiple WP Sidebars”


  1. Richard Giles Says:
    March 30th, 2010 at 10:02 am

    Hi,

    I use Wordpress as a CMS. Any chance you could post a step-by-step tutorial on how to create a sidebar that displays just for the blog?

    Many thanks

Leave a Reply

Contact Us Today...

For more information regarding any of our services or to arrange a free consultation simply send us a message or call 02920 290 080 for Cardiff and 01179 000 482 for Bristol.

Firefox 4 Beta

Mozilla have released the first beta version of Firefox 4. The latest version of this browser will include better support for many of the new web technologies, a new add on manager, crash protection from third party plugins and accelerated hardware support. One of the most obvious changes is that the tabs have now been moved [...]
» more

Cardiff: 02920 290 080 Bristol: 01179 000 482