Wordpress Should Update get_sidebar to Work With Multiple Sidebars

Posted by Aaron D. Campbell | Thursday, January 10th, 2008
, ,

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.

Related Posts