Multiple Sidebar Registration Help

Community Forums Forums Design Tips and Tricks Multiple Sidebar Registration Help

This topic is: not resolved

This topic contains 9 replies, has 2 voices, and was last updated by  SoZo 1 year, 6 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #16526

    fortyfivecreative
    Participant
    Post count: 10

    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
    David

    #16531

    SoZo
    Moderator
    Post count: 1573

    You 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

    #16539

    fortyfivecreative
    Participant
    Post count: 10

    Thanks. 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’);

    #16542

    SoZo
    Moderator
    Post count: 1573

    Well, 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

    #16544

    fortyfivecreative
    Participant
    Post count: 10

    Thanks 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
     

    #16547

    SoZo
    Moderator
    Post count: 1573

    Not 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

    #16549

    fortyfivecreative
    Participant
    Post count: 10

    Sorry, 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

     

    #16550

    SoZo
    Moderator
    Post count: 1573

    It should


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

    #16552

    fortyfivecreative
    Participant
    Post count: 10

    Great, thanks for all your help. Much appreciated.

    David

    #16554

    SoZo
    Moderator
    Post count: 1573

    You’re welcome :)


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Multiple Sidebar Registration Help’ is closed to new replies.