Welcome! To use this support forum, please Login or Join Today!

   

Change Main navigation

{name}
Rank

Total Posts: 2

Joined 2013-05-13

PM

 

What is the best way to change Main Navigation menu based on selection in Top Navigation menu?

{name}
RankRankRankRank

Total Posts: 3667

Joined 2011-04-27

PM

 

Can you elaborate?
Are you wanting to just change the menu or change the menu based on a conditional statement?


If the latter, first you’ll need to create the menus so they can be interchangeable.

In this example, say you wanted to show a completely different menu on your About and Services pages. To do this, open onyx/lib/functions/theme_functions.php and look for the wp_nav_menu() function around line #50. This is where your menus can be loaded on conditional logic.

Notice the ‘menu’ => ‘About Menu’ parameter. This example assumes you have three menus:
“About Menu”, “Services Menu” and “Main Menu”.

Example:

// make sure function exists (older versions of WP)
if (function_exists('wp_nav_menu' )) {

 // If we're on the "About" page
 if (is_page( 'about' )) {
  wp_nav_menu( array('menu' => 'About Menu', 'theme_location' => 'main-menu', 'depth' => '3', 'fallback_cb' => 'st_navbar_fallback'));

 // If we're on the "Services" page
 } elseif (is_page( 'services' )) {
  wp_nav_menu( array('menu' => 'Services Menu', 'theme_location' => 'main-menu', 'depth' => '3', 'fallback_cb' => 'st_navbar_fallback'));

 // Load the default menu otherwise
 } else {
  wp_nav_menu( array('menu' => 'Main Menu', 'theme_location' => 'main-menu', 'depth' => '3', 'fallback_cb' => 'st_navbar_fallback'));
 } // endif

// if function does not exist (older versions of WP)
} else {
st_navbar_fallback();
}
echo "</div></div>";

You can also use id or slug for the menu parameter. I used “name” in this example for clarity.

http://codex.wordpress.org/Function_Reference/wp_nav_menu#Parameters
$menu (string) : The menu that is desired; accepts (matching in order) id, slug, name

{name}
Rank

Total Posts: 2

Joined 2013-05-13

PM

 

I am porting content-rich website with fairly large number of pages.  Pages to be full-page-wide. No sidebars for navigation.

On selection in Top nav new preconfigured menu is selected for Main nav.  This Main nav guides through selected group of pages.  In essence each Top nav selects a “mini-sites”: “products”, “how-to”, etc.

Can you suggest a better way to do this?  Maybe another menu Plug-in? 

Thanks

{name}
RankRankRankRank

Total Posts: 3667

Joined 2011-04-27

PM

 

Please see my (edited) reply above on how to change the menu dynamically.

Just a suggestion; I don’t know the nature of your content/navigation so I can’t be certain, but changing the persistant navigation seems like it might create a poor user experience. I know you said you have no sidebars, but maybe the subnavigation should be shown either within the content or in a sidebar?

{name}
Rank

Total Posts: 2

Joined 2013-05-13

PM

 

Thanks Casye.  My bad. Somehow I saw only the begining of your reply.
Appreciate your advice on user experience. I might rethink this approach.