Welcome! To use this support forum, please Login or Join Today!
You are here → Home :: Forum Home :: WordPress Themes Support :: Breeze WordPress Theme :: Thread
Adding more nav menus to the Breeze theme
Hi, I’m using the Breeze theme to create a site and ran across a valid need for sections with their own submenus. I know this is outside the scope of regular support but I thought I’d see if there was a simple, easy answer before I went farther.
I started by adding one section and created the appropriate section menu in Appearance/Menus, then found where you registered the default menu and added the other one there manually (why does WP not auto-register new menus created in the Admin panel? weird).
However, I’m not sure how to actually get the menu into the st_navbar() function, as it got kind of complex. I’m ok with just adding the menu manually to the header and using the conditional to switch between st_nav_menu and the others, since every section will have its own page template and I can conditional that.
Even if I do that though, how do I get the new menu to pick up the same formatting as the Breeze menu to maintain a consistent look and feel? As I said, the st_navbar() function got a little complex for me, and I’m not all that up on wp_nav_menu’s syntax either - the documentation on it is pretty generic.
Again, I know this is outside of normal support, so I thank you for any help you can give.
David
Hi, I’ll do my best to help, however I’d need to know exactly what you’re wanting to do. If my assumption below is incorrect, can you maybe explain a little more? When you say “sections” are you referring to Pages with Subpages or Post Categories?
since every section will have its own page template and I can conditional that
From the sounds of the above, I’m assuming you mean Pages.
Go ahead and make a backup of theme_functions.php
Next, find the st_addmenus function and replace with this as an example:
/* * WP 3.0 Menus */ function st_addmenus() { register_nav_menus( array( 'main-menu' => 'Main Navigation', 'menu1' => 'About Menu', 'menu2' => 'Services Menu', 'menu3' => 'Contact Menu', 'menu4' => 'Products Menu' )); } add_action( 'init', 'st_addmenus' );
Now, scroll down to the next occurrence of “if (function_exists(‘wp_nav_menu’)) {”.
Replace that line and every line in between all the way up to just before the “st_navbar_fallback” function.
if (function_exists('wp_nav_menu')) { global $post; $current_page = $post->post_name; switch ($current_page) { // About Us page case 'about-us': $mymenu = 'menu1'; break; // Services case 'services': $mymenu = 'menu2'; break; // Contact case 'contact': $mymenu = 'menu3'; break; // Products case 'products': $mymenu = 'menu4'; break; // All other pages default: $mymenu = 'main-menu'; } if ($showcaptions == 'true') { wp_nav_menu( array('theme_location' => $mymenu, 'depth' => '3', 'fallback_cb' => 'st_navbar_fallback', 'walker' => new st_primary_walker())); } else { wp_nav_menu( array('theme_location' => $mymenu, 'depth' => '3', 'fallback_cb' => 'st_navbar_fallback')); } } else { st_navbar_fallback(); } echo "</div></div>"; }
So, looking at the code above, each page will have a different menu based on the page slug, falling back to main-menu as default.
Is this what you need?
Wow, that’s a lot more than I needed, thanks! I only needed to know how to get more menus tied into the formatting of st_navbar, but this gives me a whole solution. Thanks!
One thing still unclear, and it’s not your code, it’s because of WP’s gap in the documentation on this function. Can you tell me which name created by the Menus panel corresponds to your array values? ‘Main Navigation’ ‘About Menu’ etc. (see attached pic for my actual menus at this time).
Again, thank you for such a comprehensive reply!
I defined them in the register_nav_menus array here:
register_nav_menus( array( 'main-menu' => 'Main Navigation', 'menu1' => 'About Menu', 'menu2' => 'Services Menu', 'menu3' => 'Contact Menu', 'menu4' => 'Products Menu' ));
The register_nav_menus function is loaded in nav-menu.php.
http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/nav-menu.php
I don’t think there is a public method for the array though. It looks like it is expecting user defined input.
function register_nav_menus( $locations = array() ) { global $_wp_registered_nav_menus; add_theme_support( 'menus' ); $_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations ); }
Thanks but I meant when I create a custom menu in the Menus panel, give it a name and select it in the Theme Location dropdown, what info there corresponds to the ‘Main Navigation’, ‘About Menu’, etc. values in your example? I understand all the rest, but that one piece isn’t called out in the WP documentation I read through, so I am missing the connection between what I put into the Menus panel and this function.
I’m having trouble believing it’s the name I give it in the Menus panel, as that’s a user-editable value and can be changed at any time, and that looks like it would break the menu registration code, and therefore the site’s navigation. So if I sound obtuse on this, please don’t be too harsh on me
I think I understand what you mean…but not sure. Maybe I’m missing the question entirely.
As you know, you can name your actual menu whatever you like - then it will be selectable in the theme locations. When you create a menu, you’re actually creating a Post (believe it or not) at least that’s how WordPress stores it in the database. It gets an ID just like any other Post.
If you look in wp_nav_menu, you’ll see there is a $menu reference in the array:
http://codex.wordpress.org/Function_Reference/wp_nav_menu#Usage
$menu (string) (optional) The menu that is desired; accepts (matching in order) id, slug, name
Default: None
So, when you register a new menu using register_nav_menus, you can either specify your own:
name ($theme_location) or any Menu ($menu) you like.
($menu is not to be confused with $menu_id. These are two entirely different parameters)
No, you’ve got it. It’s me that’s hung up on the fact that the user admin panel is setting a value that must then be hard coded, and can be changed by the user afterwards, thus breaking the menu registration. Wow. That’s not something I’m used to seeing.
If you accept suggestions for themeing, I’d say WP seriously needs a function to look for and register any user-created menus with some formalized value (menu1/2/etc.). Boom, we’re done with all this functions.php editing to make menus work in the first place. Menu name changes won’t break the menus anymore since the menu will be re-registered automatically with the new name, and the formalized value creates a layer of abstraction to keep wp_nav_menus happy.
Sorry for using your time like this over a WP issue! I’ll try to stay in SimpleThemes topics from now on.
No problem. I know it’s kind of clunky. I think they were more hung up on backwards compatibility with the database than anything (which is kind of a good thing). For the longest time, WordPress didn’t even have menu options. It just displayed all of your pages and categories by default. Menus were only introduced in WordPress v.3.
Hopefully as time goes by, they’ll revisit the methods and offer more options in terms of extensibility.
Argh, just found this very useful thread - https://wordpress.org/support/topic/getting-menu-name-in-a-given-location. I did not find these on my searches on wordpress.org. I hate their search engine.
Based on this, I think I might have been mistaken and you don’t need to register the menus at all if you’re creating them in the admin panel. You can use these functions to directly get the values for wp_nav_menu to use. If so, I’m sorry for the waste of your time - you can bill me for some consulting time if you want :(