Community Forums › Forums › Archived Forums › Design Tips and Tricks › Need help displaying custom sidebar & custom menu automatically
Tagged: custom menu, custom sidebar
- This topic has 5 replies, 2 voices, and was last updated 11 years, 9 months ago by AnitaC.
-
AuthorPosts
-
December 22, 2012 at 5:28 am #6902sonjayMember
I have a multisite install, with all sites using the Lifestyle child theme. I've used Genesis Simple Sidebars to create a second alternative primary sidebar, and the Menus option to create an alternative menu for the "secondary navigation" menu area.
What I want:
The home page and every "page" (not post) should use the main primary sidebar and original secondary navigation menu, but every post and post category should use the alternative primary sidebar and alternative secondary navigation menu. Basically, the entire "blog" section of the site should have a different primary sidebar and nav menu from the home page and all other pages on the site.
It's easy enough to assign the appropriate sidebar and menu for each category and each post. But I'd prefer to have that happen automagically. This multisite install will have multiple different people working on it, some of whom will be less... shall we say .... computer-savvy than others. I want to reduce to an absolute minimum the things that they have to do when posting a new blog post or creating a new category.
Since the requirement is consistent across all sites in the multisite install, and consistent in that I always want Sidebar A and Menu A to be displayed on the home page and each "page," and Sidebar B and Menu B to be displayed on each post and post category, I'm guessing there should be something I can stick in the functions.php file using conditional logic along the lines of "if ( is_home or is_page) { Sidebar A & Menu A } elseif ( is_post or is_category ) {Sidebar B & Menu B}
Here is the site that I'm using as a testbed for this approach:
http://withblog.suncoasteam.com/
Here is the blog section, with a different menu in the green gradient nav menu and a different primary sidebar:
December 22, 2012 at 6:49 am #6909AnitaCKeymasterOff the top of my head right now, I would suggest using Widget Logic to set that up - http://wordpress.org/extend/plugins/widget-logic/. Someone else may have a better way, but take a look at this.
Need help with customization or troubleshooting? Reach out to me.
December 23, 2012 at 10:32 am #7168sonjayMemberThanks for the suggestion. That plugin probably would have accomplished what I needed for the sidebar, but not for the menu. But after looking at the code in the plugin, and doing some more reading in the genesis help files, I figured out what I needed. I'll post it here in case anyone else needs to do the same thing:
For the custom sidebar, I copied the sidebar.php file from the genesis directory to my Lifestyle theme directory, and stuck this code in my sidebar.php file, replacing the line "do_action( 'genesis_sidebar' );"
if ( is_single() || is_archive() || is_page('blog') ) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'my_genesis_do_blog_sidebar' );
function my_genesis_do_blog_sidebar() {
dynamic_sidebar( 'blogsidebar' );
}
do_action('genesis_sidebar');
} else {
do_action( 'genesis_sidebar' );
}
}
For the menu, I stuck this in my functions.php file:
remove_action('genesis_after_header', 'genesis_do_subnav');
add_action('genesis_after_header','my_custom_subnav');
function my_custom_subnav () {
if ( is_single() || is_archive() ) {
echo '<div id="subnav"><div>';
wp_nav_menu( array('menu' => 'TopGreenBarForBlogSection' ));
echo '</div></div>';
} else {
genesis_do_subnav();
}
}
December 23, 2012 at 10:36 am #7169AnitaCKeymasterThat's great. It's like a recipe.. just need the right ingredients to make it work.
Need help with customization or troubleshooting? Reach out to me.
December 23, 2012 at 10:49 am #7170sonjayMemberExcept, sorry, bits of the code got transformed -- you'll have to mentally change all those ≶ and > bits into
(hope the same thing doesn't happen again. if it does, you'll have to be smart enough to just know what I mean)
(and why isn't there a preview in this forum, so that I can at least see if things are correct before hitting Submit?)
December 23, 2012 at 10:51 am #7171 -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.