Community Forums › Forums › Archived Forums › General Discussion › Metro Theme How to Replace Primary Sidebar for home.php Only
Tagged: Metro theme.
- This topic has 7 replies, 2 voices, and was last updated 10 years, 7 months ago by Andrew Hand.
-
AuthorPosts
-
August 26, 2013 at 2:15 pm #58904Andrew HandMember
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.comAugust 26, 2013 at 3:46 pm #58924AnitaKeymasterWhat 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."
Love coffee, chocolate and my Bella!
August 26, 2013 at 3:52 pm #58929Andrew HandMemberHey, 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:
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' ); }
August 26, 2013 at 3:58 pm #58930AnitaKeymasterWithout 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.
Love coffee, chocolate and my Bella!
August 26, 2013 at 4:03 pm #58932Andrew HandMemberHey, 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.
August 26, 2013 at 4:06 pm #58934AnitaKeymasterThen I think using Widget Logic will probably work best for you.
Love coffee, chocolate and my Bella!
August 26, 2013 at 4:17 pm #58936Andrew HandMemberIt 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!
August 26, 2013 at 4:26 pm #58937Andrew HandMemberJust 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):
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' ); }
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.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.