[wp-hackers] Wondering about this possible mod to core get_sidebar
Claude Needham
gxxaxx at gmail.com
Wed Aug 17 18:36:58 UTC 2011
Below is code I've been testing for a possible enhancement to the
get_sidebar core function.
Reason for mod: I wanted to pass in an array of declining alternatives
for the sidebar. This will take advantage of the power of
locate_template.
I'm pretty darn new to php, and very new to wordpress. Meaning, I
would not be surprised if there is a more bullet proof way to do this.
Even so, I wanted to run this idea by a few folks. To see if it is
worth trying to propose to the core guys.
Regards,
Claude Needham
p.s. A similar mod would be equally handy in get_footer
function get_sidebar( $name = null ) {
do_action( 'get_sidebar', $name );
$templates = array();
if ( isset($name) ) {
if (is_array($name)) {
foreach ( (array) $name as $disname ) {
if ( !$disname ) { continue; }
$templates[] = "sidebar-{$disname}.php";
}
} else {
$templates[] = "sidebar-{$name}.php";
}
}
$templates[] = 'sidebar.php';
// Backward compat code will be removed in a future release
if ('' == locate_template($templates, true))
load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
}
More information about the wp-hackers
mailing list