Community Forums › Forums › Archived Forums › Design Tips and Tricks › conditional secondary menu
Tagged: conditional menu
- This topic has 5 replies, 3 voices, and was last updated 7 years, 8 months ago by Genesis Developer.
-
AuthorPosts
-
August 6, 2016 at 3:33 pm #190840bburroMember
Greetings all! I am looking for a little help on a piece of code for my functions.php file. Here's what I'n trying to do:
If page ID = (pageID1, pageID2, pageID3) => display secondary menu 1;
If page ID = (pageID3, pageID4, pageID5) => display secondary menu 2;
Else do not display secondary menu.
I am using the showcase 3rd party template, and haven't heard back from the author.
Thanks in advance!
http://localhostAugust 6, 2016 at 4:15 pm #190842Victor FontModeratorhttp://victorfont.com/conditional-secondary-menus-genesis-themes/
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 6, 2016 at 5:23 pm #190847bburroMemberVictor- I was looking at the revisited version of your page and my coding skills weren't up to connecting the dots.-
Let me give this one a go. Thanks!
August 6, 2016 at 5:33 pm #190849bburroMemberMy coding skills are meager at best. One of the menus I want to use has an ID of menu-hydrovac-menu.
What would the code be to use that menu on pages with IDs of 1,4 &5?
I can take that and create the other blocks.
Also, what would the last part be that says "otherwise don't display a secondary menu"?
Thanks again for the help!
August 6, 2016 at 6:05 pm #190851bburroMemberIt looks like what I want is more like the version on your revisited page, except I want default to be NO SECONDARY NAV.
What variable are you passing as Menu1, Menu2? Is that the ID?
How do I assign multiple page IDs? separate them by a comma?
How do I default to where if none of the IDs I have selected, then no secondary nav?The following is the code from your site I am referring to, just to make sure we are on the same page.
Thanks again!
//* When a new page is selected from the primary menu, //* execute the change_secondary_menu function add_action( 'template_redirect', 'change_secondary_menu' ); function change_secondary_menu() { //* Do nothing if menu not supported if ( ! genesis_nav_menu_supported( 'secondary' ) ) return; add_filter( 'wp_nav_menu_args', 'choose_secondary_nav_menu' ); } function choose_secondary_nav_menu( $args ) { if ( $args['theme_location'] == 'secondary' ) { //* default secondary menu $args['menu'] = 'Menu1'; if( is_page( 37 ) ) { $args['menu'] = 'Menu2'; } if( is_page( 39 ) ) { $args['menu'] = 'Menu3'; } } return $args; }
August 6, 2016 at 11:03 pm #190852Genesis DeveloperMemberThis can give you the idea http://genesisdeveloper.me/different-primary-menu-on-pages-using-altitude-pro-theme/
I think that you do not need the 'template_redirect' action. You ca directly target the 'wp_nav_menu_args' filter.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.