• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Multiple Sidebar Registration Help

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Multiple Sidebar Registration Help

This topic is: not resolved

Tagged: Array, function, multiple, Sidebar

  • This topic has 9 replies, 2 voices, and was last updated 10 years ago by SoZo.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • January 30, 2013 at 4:07 pm #16526
    fortyfivecreative
    Member

    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

    January 30, 2013 at 4:11 pm #16531
    SoZo
    Member

    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

    January 30, 2013 at 4:28 pm #16539
    fortyfivecreative
    Member

    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');

    January 30, 2013 at 4:33 pm #16542
    SoZo
    Member

    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

    January 30, 2013 at 4:39 pm #16544
    fortyfivecreative
    Member

    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
     

    January 30, 2013 at 4:45 pm #16547
    SoZo
    Member

    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

    January 30, 2013 at 4:56 pm #16549
    fortyfivecreative
    Member

    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

     

    January 30, 2013 at 4:57 pm #16550
    SoZo
    Member

    It should


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

    January 30, 2013 at 4:59 pm #16552
    fortyfivecreative
    Member

    Great, thanks for all your help. Much appreciated.

    David

    January 30, 2013 at 5:01 pm #16554
    SoZo
    Member

    You're welcome 🙂


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

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Multiple Sidebar Registration Help’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble