Metro Theme How to Replace Primary Sidebar for home.php Only

Community Forums Forums General Discussion Metro Theme How to Replace Primary Sidebar for home.php Only

This topic is: not resolved

Tagged: 

This topic contains 7 replies, has 2 voices, and was last updated by  Andrew Hand 1 year ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #58904

    Andrew Hand
    Participant
    Post count: 6

    Hey guys,

    So I’m using the Metro child theme and wanting to have a unique sidebar just for home.php and NOT the Primary Sidebar. I’ve tried several approaches from StudioPress users but nothing’s worked.

    I’m good with registering sidebars but haven’t had any luck removing the primary and replacing it with a custom one. Thanks for the help in advance!

    http://learntoplayguitartv.com
    #58924

    Anita
    Participant
    Post count: 7550

    What other approaches have you tried from other users? This would help so we don’t provide the same thing and your response won’t be, “I’ve tried that already.”


    When asking for help, please provide a link or screen shot showing your problem!
    Let me help you customize your theme, responsive header, Buddypress, Agentpress or technical issue!
    Visit me here: Cre8tiveDiva.com | Tweet Me!

    #58929

    Andrew Hand
    Participant
    Post count: 6

    Hey, so I currently used Jennifer Baumann’s code for adding a custom sidebar to all post and page types to eliminate the Primary Sidebar from displaying, hence it only ends up being used on home.php

    It’s super Frankenstein and backwards but it’s reverse elimination since I couldn’t find any other way to do it the more logical way…

    That being alter home.php to use a custom sidebar rather than the primary sidebar and then put the widgets used in my replacement sidebars and drop them back into the primary sidebar.

    Whew…hope that made sense :-)

    Here’s Jen’s code:

    [php]add_action( ‘get_header’, ‘child_sidebar_logic’ );
    /**
    * Swap in a different sidebar instead of the default sidebar.
    *
    * @author Jennifer Baumann
    * @link http://dreamwhisperdesigns.com/?p=1034
    */
    function child_sidebar_logic() {
    if ( is_page_template( ‘page_blog.php’ ) || is_archive() || is_404() || is_single() ), get_post_type() ) {
    remove_action( ‘genesis_after_content’, ‘genesis_get_sidebar’ );
    add_action( ‘genesis_after_content’, ‘child_get_blog_sidebar’ );
    }
    }

    /**
    * Retrieve blog sidebar
    */
    function child_get_blog_sidebar() {
    get_sidebar( ‘content’ );
    }[/php]

    #58930

    Anita
    Participant
    Post count: 7550

    Without hacking the code – you could install Genesis Simple Sidebars as an option. Leave the Primary sidebar for the home and create a new sidebar with the plugin for the internal pages – http://wordpress.org/plugins/genesis-simple-sidebars/.

    You could also install Widget Logic – http://wordpress.org/plugins/widget-logic/. Add the widgets you want for the home page in the Sidebar and configure the widget to only show up on the home page.


    When asking for help, please provide a link or screen shot showing your problem!
    Let me help you customize your theme, responsive header, Buddypress, Agentpress or technical issue!
    Visit me here: Cre8tiveDiva.com | Tweet Me!

    #58932

    Andrew Hand
    Participant
    Post count: 6

    Hey, so I already have Simple Sidebars installed. The problem is that the Metro theme will display the Primary sidebar on 404 pages, archive pages, etc, so while Jen’s code fixes this, and it’s worked fine, it breaks with a bbpress installation, which I just added and hence reached this new challenge.

    The ideal solution is to simply alter the home.php code. The Home page needs to have a sidebar NOT used by any other pages, i.e. archives, 404, bbpress pages, etc.

    The point of this is for the Home Page to be a squeeze page and have a unique opt-in form only used there. The “in-site” content is meant to have a full sidebar with several other widgets in it.

    Hope that makes sense.

    #58934

    Anita
    Participant
    Post count: 7550

    Then I think using Widget Logic will probably work best for you.


    When asking for help, please provide a link or screen shot showing your problem!
    Let me help you customize your theme, responsive header, Buddypress, Agentpress or technical issue!
    Visit me here: Cre8tiveDiva.com | Tweet Me!

    #58936

    Andrew Hand
    Participant
    Post count: 6

    It seems like adding in even more code to be output isn’t the best answer. I just altered Jen’s code to strip the conditional statement and added it to home.php and removing it from the functions.php file.

    This works in rendering that custom sidebar I created only on the Home Page. All I had to do was swap the widgets between my Primary Sidebar and custom one.

    The issue I wonder about is Jen’s own statement that her code is outdated and there’s an even easier way to accomplish this other than having a sidebar-content.php file, registering the sidebar in functions.php and now calling it in home.php.

    I’m wondering WHAT that easier and “better” way is.

    Thanks for the ideas!

    #58937

    Andrew Hand
    Participant
    Post count: 6

    Just to summarize what works here. Jen’s post located here:

    http://dreamwhisperdesigns.com/genesis-tutorials/load-sidebar-specific-pages/

    Altering this code to be this (removing the conditional statement from the original):

    [php]add_action( ‘get_header’, ‘child_sidebar_logic’ );
    /**
    * Swap in a different sidebar instead of the default sidebar.
    *
    * @author Jennifer Baumann
    * @link http://dreamwhisperdesigns.com/?p=1034
    */
    function child_sidebar_logic() {
    remove_action( ‘genesis_after_content’, ‘genesis_get_sidebar’ );
    add_action( ‘genesis_after_content’, ‘child_get_blog_sidebar’ );
    }

    /**
    * Retrieve blog sidebar
    */
    function child_get_blog_sidebar() {
    get_sidebar( ‘content’ );
    }[/php]

    This works to replace the Primary Sidebar with this custom one I created as seen in sidebar-content.php that Jen’s tutorial walks you thru and put in home.php rather than functions.php

    This method works and will solve the issue of allowing home.php to have a unique sidebar only used there. The issue is wondering what the “much easier” way of doing this that she mentions is.

    Hope this helps anyone else trying to accomplish the same thing and I have to thank Nick from StudioPress support for telling me that moving this to home.php would accomplish the goal.

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

You must be logged in to reply to this topic.