For one of my sites, the person wanted to use two different sidebars: one for his store and another for his blog. The rest of the site was full-width layout. So we used the two sidebars: Primary (sidebar) and Secondary (sidebar-alt). So here's how to switch sidebars (without using Nathan's phenomenal plugin Simple Sidebars) using functions.php.
[php]//switch sidebars
add_action('get_header','change_genesis_sidebar');
function change_genesis_sidebar() {
$pages = array(181);
if ( is_page($pages)) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'genesis_do_sidebar_alt' );
}
} [/php]
This code can be easily adapted to be done based on category, archives, author, etc. See the conditional tags for more details.
Jenny says
Travis,
I think this function: add_action( ‘genesis_sidebar’, ‘genesis_do_sidebar_alt’ ); is the major part of the coding. I think alt is for secondary sidebar right? Thank you for this nice post.
Travis Smith says
add_action( ‘genesis_sidebar’, ‘genesis_do_sidebar_alt’ ); only adds the Secondary Sidebar (and yes alt stands for the Secondary Sidebar). However, you still need to remove the primary and apply any conditions if you want them. Otherwise you may want to consider forcing a particular layout if you just want to add the secondary sidebar on certain pages.