Multiple WordPress Sidebars
wordpress
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.
It appears you are new around here. You may want to subscribe to my RSS feed or register for email updates. Thanks for visiting!
Related Posts





















November 5, 2008 @ 8:26 pm
Thanks for the info!
[Reply]