January 10th, 2008 Wordpress Should Update get_sidebar to Work With Multiple Sidebars
I submitted an enhancement to wordpress yesterday, to allow get_sidebar to work with multiple sidebars. It’s an extremely simple fix, and you end up with a function that looks like this:
function get_sidebar($name=null) { do_action( 'get_sidebar' ); if ( isset($name) && file_exists( TEMPLATEPATH . "/sidebar-{$name}.php") ) load_template( TEMPLATEPATH . "/sidebar-{$name}.php"); elseif ( file_exists( TEMPLATEPATH . '/sidebar.php') ) load_template( TEMPLATEPATH . '/sidebar.php'); else load_template( ABSPATH . 'wp-content/themes/default/sidebar.php'); }
By adding two lines and one optional parameter to the get_sidebar() function, you would be able to pass it a sidebar name. For example, get_sidebar(’left’) would load the template TEMPLATEPATH . ’sidebar-left.php’ allowing you to have multiple sidebar files as part of your template.
When I redesigned Xavisys a while ago, I organized the content as center, left, right. This allowed me to put both sidebars into one sidebar.php file. Then I ran into the Internet Explorer peekaboo bug, and realized I would need to reorder the content as left, center, right. When I looked into how to best accomplish that in wordpress, I realized how simple it would be to adjust the get_sidebar function to handle it, without altering it’s current functionality at all. I actually find it hard to believe that it’s not already in the code. Hopefully it will make it into the 2.5 release.
John Says:
Neat… thks for the hack.. I’ve been looking for this. Is there a way to enable the admin’s ‘widgets’ page switch between multiple sidebars ?
Aaron D. Campbell Says:
Yes, if you register multiple sidebars, it will show multiple sidebars. I usually register them in functions.php (in the theme) like this:
register_sidebar(array('name'=>'left'));register_sidebar(array('name'=>'right'));
Then in each sidebar, you need to use the name when calling dynamic sidebar, like this:
dynamic_sidebar('left');John Says:
Hi Aaron,
Thanks for the help… really appreciate it so much ^^ .. that now I can show that off to my boss *:evil laugh*
Aaron D. Campbell Says:
No problem. You took the time to find the answer, you deserve the credit!