Ever had a layout with two or more sidebars? The standard convention is to put both sidebars inside sidebar.php if they’re beside each other, or one in header.php and the other in the standard sidebar template. However, there’s a quick little WordPress trick that actually allows for two separate sidebar templates.
You’ll need two files: sidebar.php and sidebar-right.php. The first will contain the first sidebar on the left of the page, and the second, obviously, contains the area for the right of the page.
Now, in your template files, you can use the <?php get_sidebar(); ?> function to call the left sidebar, as usual. But now that you’ve added a second file, <?php get_sidebar('right'); ?> can be used to call the “right” sidebar file from the template. Note: the “right” file is the only file that seems to work; ‘sidebar-left’ will not.
Post Revisions:
- 16 August, 2010 @ 11:09 [Current Revision] by dan philibin
- 6 August, 2010 @ 4:12 by Ryan Imel
- 1 November, 2008 @ 6:00 by Ryan Imel
Posted November 1, 2008
Bramme said:
If you would look up the get_sidebar function, there’s probably a way to hack into accepting all kinds of sidebar files. Quite possible this is doable with a plugin, however ,I’ve never created wordpress plugins.
on November 1, 2008 at 6:47 am
Ryan Imel said:
One tiny suggestion. Maybe call the secondary sidebar something like sidebar-seconday.php, or something similarly generic? If the sidebar, then, is ever switched from one side of the page to the other, this call won’t be confusing.
This might be my desire for semantic XHTML markup bleeding over into my PHP a bit, but I’d like to think the two languages can share some principles.
Nice tip, definitely handy when the situation calls for it.
on November 1, 2008 at 6:56 am
Dan Philibin said:
From my understanding, the name is a requirement, so if you wanted to call it something different that’s something WordPress would have to change. Good idea, though.
on November 1, 2008 at 9:03 am
DVQ said:
Why wouldn’t you just use .
This way you could name the sidebar whatever you wanted.
on November 1, 2008 at 4:37 pm
DVQ said:
It appears my code was stripped from the comment above.
What I mean is why not just use php include (‘sidebar-2.php’);
on November 1, 2008 at 8:49 pm
Dan Philibin said:
Hmm – I thought when I read the article in the Codex that it mentioned
get_sidebar('right');was the only one that worked. Maybe you can add anything after the hyphen – can anyone confirm that?on November 1, 2008 at 8:52 pm
Rick Overman said:
The only gotcha with multiple sidebars is that a lot of widgets (including ones in the wordpress install) are NOT multi-widgets — which means there can only be one used once and cannot be added to additional sidebars. Not a problem in the simple example above but if you start having a lot of side bars on different pages then it’s a huge pain.
I am going to release a free theme framework (OnePress Community) in the next week that will fix all the default widgets, add a few new cool ones and allow multiple sidebars and page customization and support phpBB user integration. The site is http://OnePressCommunity.com and should launch second week of November.
on November 3, 2008 at 1:27 pm
mit said:
i want 3 columns theme releted to http://www.theraider.net/ this site theme
on December 12, 2009 at 6:27 am