How to assign a different sidebar to the homepage?

Community Forums Forums Design Tips and Tricks How to assign a different sidebar to the homepage?

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  glasertech 1 year, 10 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8938

    glasertech
    Participant
    Post count: 5

    Hello,

    We need a special sidebar for the homepage. We tried to use the “Genesis – Simple Sidebars” plugin, but we cannot assign the new sidebar to the hompage.

    Another solution could be to assign a different sidebar as the primary sidebar to ALL post pages.

    Is there a solution with not too much coding effort and keeping the automatical upgrade capability?

    Thank You in advance,
    Max Glaser

    #8942

    Chris Cree
    Participant
    Post count: 147

    Which theme are you using, Max? Also it would help to share a link to your site when asking for help here.

    In the meantime, I think this should work in most cases. Add this to your functions.php file.
    [php]add_action( ‘get_header’, ‘child_home_sidebar_switch’ );
    function child_home_sidebar_switch() {
    if( is_front_page() ) {
    remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’ );
    genesis_widget_area( ‘home-sidebar’);
    }
    }[/php]

    You will also need to add the new home-sidebar to your functions.php file too. Here’s the code to do this.

    [php]genesis_register_sidebar( array(
    ‘id’ => ‘home-sidebar’,
    ‘name’ => __( ‘Home Sidebar’, ‘genesis’ ),
    ‘description’ => __( ‘This is the Homepage Sidebar.’, ‘genesis’ ),
    ) );[/php]


    #8946

    glasertech
    Participant
    Post count: 5

    Chris,

    Thank you for your answer. We are using the news theme. I already added your code on the functions.php file in the news themes directory, an I can see the “Home Sidebar”, but how can I assign it to the homepage?

    #9008

    glasertech
    Participant
    Post count: 5

    Chris,

    Thank You! Finally I understood the Genesis Hook and Sidebar APIs :-)

    My solution is to add into the file functions.php in the child’s theme directory the following code:


    add_action( 'get_header', 'child_home_sidebar_switch' );
    function child_home_sidebar_switch() {
    if( is_front_page() ) {
    remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
    add_action( 'genesis_after_content', 'child_get_home_sidebar' );
    }
    }

    function child_get_home_sidebar() {
    echo '';
    get_sidebar( 'home' );
    echo '';
    }

    and to create the following new file sidebar-home.php also in the child’s theme directory

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

You must be logged in to reply to this topic.