Community Forums › Forums › Archived Forums › Design Tips and Tricks › Multiple Sidebar Registration Help
- This topic has 9 replies, 2 voices, and was last updated 11 years, 8 months ago by SoZo.
-
AuthorPosts
-
January 30, 2013 at 4:07 pm #16526fortyfivecreativeMember
Hi, wondered if you could help with the code to register three sidebars in this array, instead of one:
genesis_register_sidebar(
array
(
'name'
=>
'Sidebar Name'
,
'description'
=>
'Description'
,
'id'
=>
'sidebar-id'
));
Thanks
DavidJanuary 30, 2013 at 4:11 pm #16531SoZoMemberYou add the register code three times. You don't register multiple sidebars in one register action
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 4:28 pm #16539fortyfivecreativeMemberThanks. I actually think I need to ask about 'best practice' for adding the new sidebars. I've used the following code to add the sidebars without any additional PHP files, but not sure whether this is better or worse than doing this via sidebar-xx.php:
//* 45: Create and add new sidebars */
genesis_register_sidebar( array(
'id' => 'single-post-sidebar',
'name' => __( 'Single Post Sidebar', 'genesis' ),
'description' => __( 'This is the single post sidebar.', 'genesis' ),
) );genesis_register_sidebar( array(
'id' => 'category_archive_sidebar',
'name' => __( 'Category Archive Sidebar', 'genesis' ),
'description' => __( 'This is the category archive sidebar.', 'genesis' ),
) );genesis_register_sidebar( array(
'id' => 'tag_archive_sidebar',
'name' => __( 'Tag Archive Sidebar', 'genesis' ),
'description' => __( 'This is the tag archive sidebar.', 'genesis' ),
) );function single_post_sidebar() {
echo '<div id="sidebar" class="sidebar widget-area">';
dynamic_sidebar( 'single-post-sidebar' );
echo '</div>';
}function category_archive_sidebar() {
echo '<div id="sidebar" class="sidebar widget-area">';
dynamic_sidebar( 'category_archive_sidebar' );
echo '</div>';
}function tag_archive_sidebar() {
echo '<div id="sidebar" class="sidebar widget-area">';
dynamic_sidebar( 'tag_archive_sidebar' );
echo '</div>';
}function include_new_sidebar() {
if ( is_single() ) {
remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
add_action( 'genesis_after_content', 'single_post_sidebar' );
} else if ( is_category() ) {
remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
add_action( 'genesis_after_content', 'category_archive_sidebar' );
} else if ( is_tag() ) {
remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
add_action( 'genesis_after_content', 'tag_archive_sidebar' );
}
}
add_action('get_header', 'include_new_sidebar');January 30, 2013 at 4:33 pm #16542SoZoMemberWell, my 2 cents is that putting everything in functions.php saves a template call. While not that big of a drain on resources why add it? Unless of course your functions file is starting to get out of hand then it may be easier to make sense of what is going on by separating things out into different templates but that is only for you looking at and making sense of the code. From a computer's standpoint it's much better to have everything in one file.
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 4:39 pm #16544fortyfivecreativeMemberThanks again, and can I finally just ask you to check the sytnax of these parts of the code:
function category_archive_sidebar() {
echo ‘<div id=”sidebar” class=”sidebar widget-area”>’;
dynamic_sidebar( ‘category_archive_sidebar’ );
echo ‘</div>’;
}
AND
remove_action( ‘genesis_after_content’, ‘genesis_get_sidebar’ );
add_action( ‘genesis_after_content’, ‘single_post_sidebar’ );Are these complete and inline with the latest framework CSS structure?
Thanks
David
January 30, 2013 at 4:45 pm #16547SoZoMemberNot sure what you mean by the CSS structure. Do you mean applying an id of sidebar and a class of sidebar? If so then yes, that is how the primary sidebar is coded.
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 30, 2013 at 4:56 pm #16549fortyfivecreativeMemberSorry, wasn't clear, I just meant will:
echo ‘<div id=”sidebar” class=”sidebar widget-area”>’;
dynamic_sidebar( ‘category_archive_sidebar’ );
echo ‘</div>’;
...create a complete sidebar with all the correct CSS?Thanks again
David
January 30, 2013 at 4:57 pm #16550SoZoMemberJanuary 30, 2013 at 4:59 pm #16552fortyfivecreativeMemberGreat, thanks for all your help. Much appreciated.
David
January 30, 2013 at 5:01 pm #16554SoZoMember -
AuthorPosts
- The topic ‘Multiple Sidebar Registration Help’ is closed to new replies.