function meaning
Wp_nav_menu ()
Custom menu Display function
Register_nav_menu ()
Custom menu Registration Function-singular
Register_nav_menus ()
Custom Menu Registration function – Complex number (a complex form of a pain in the egg)
The following examples are used in the plural form of register_nav_menus () to avoid confusion.
Use location
Register_nav_menus ()
function.php file, the code call name and the background display name used to register the custom menu in the background.
Wp_nav_menu ()
The topic is arbitrary where you want to invoke the custom menu.
How to use
Register 4 Menu corrections: 3 Menus (sleepy, old mistakes.) )
Register_nav_menus (
' nav1 ' => ' N1 ',
//nav1 for menu name (when invoked)
//n1 for display name, background menu selection with
' nav2 ' => ' N2 ',
' nav3 ' => ' n3 ')
;
Then go to your backstage = "appearance =" menu inside Look,
Basically, you know,
If you don't understand,
Then you take another look, hey!
Topic you want to show the location of the custom navigation add the following code.
Call NAV1 's menu
<?php wp_nav_menu (Array (' theme_location ' => ' nav1 '));?>
//Invoke Nav2 's menu
<?php wp_ Nav_menu (Array (' theme_location ' => ' nav2 '));?>
Then you can go to the background to add a menu, (preferably the name of the name or Chinese.) Correction: It is best to be in English. )
You can set what the menu shows, what not to display, and even set the level of navigation, it is convenient to say.
Filter out unused class values in custom menus
in the custom menu of WordPress's output, each child element in the menu has a very long class value, although from the appearance can not see anything strange, but from the code to see it really uncomfortable, in fact, to filter out these class values have a lot of methods, Today, to get rid of the class that we don't want by mounting the filter (filter).
In the future version of WordPress 3.5.0 will be canceled link function, and to customize the menu function to achieve, this is something.
When we output the custom menu, in order to let us better control the custom style, WordPress will default to our menu child elements output a number of class values, like the following.
<li id= "menu-item-19" class= "Menu-item menu-item-type-post_type menu-item-object-page menu-item-19" >
How to filter, so that our web page source code to become concise, easy to read it?
Join in your functions.php.
function Filter_nav_menu_css_class ($classes) {
//The class value that you want to pass
$do _class_name = Array (' Current-menu-item ');
$outPut = Array_intersect ($do _class_name, $classes);
Array_filter ($classes);
return $outPut;
};
Add_filter (' Nav_menu_css_class ', ' filter_nav_menu_css_class ');
Here Current-menu-item this value is reserved primarily to identify the current page.
In fact
There are other ways to filter out the class values of the output,
For example, control Walker_nav_menu this class to precisely control the output of custom menus,
But because of the more troublesome so not to mention here, in fact, Walker_nav_menu this class can do more of the functions we need.
Summary – Need to be aware
custom menu in WordPress 3.0 after the introduction of a functional concept, somewhat similar to the previous gadget, but the custom menu is more inclined to navigation purposes, but because the new features of the Chinese translation, slow circulation, Plus this feature as long as the theme is shaped by the love toss the blogger will generally not toss in the navigation aspect, so we still do not understand, and even have a wrong tutorial flying in the situation, here hope that some bloggers in the post when not to reprint the main, even if it is reproduced some major functions please specific test, To avoid misleading new people.
Need to note:
In the background settings, if you don't set a menu for a custom navigation, that WP will automatically add all pages for navigation without a set menu, which is the default for a sore egg, so if the navigation we don't want to show, you'd better set an empty menu the day after Tomorrow and add this menu to the navigation you don't want to show. So that the custom navigation is not displayed.