To implement a custom menu, the function that needs to be used is wp_nav_menu ();
In the theme directory of the functions.php <?php ..... ?>, add the following menu registration code so you can use the Wp_nav_menu function in the theme file:
Register_nav_menus ();
Then the menu: "Menu" appears under appearance
To create a menu:
Click "Create New Menu", select the column you want to display, then "save Menu"
Invoke Menu:
Add the following statement to output the menu:
<?php Wp_nav_menu ();?>
The HTML for the output is:
<Divclass= "Menu-nav-container"> <ulclass= "Menu"ID= "Menu-nav"> <Liclass="..."ID= "Menu-item-1"><ahref="...">Xx</a></Li> <Liclass="..."ID= "Menu-item-2"><ahref="...">Xxx</a></Li> ... </ul></Div>
This method also provides a number of parameters, such as:
<?php wp_nav_menu (array(' menu ' = ' nav ', ' depth ' = ' 1, ' menu_class ' = ' navcontainer '));? >
Gets the menu name of NAV, listing only one level menu, style named Navcontainer
Common parameters:
Menu |
Desired menu to display |
container_id |
UL parent Node ID value |
Container_class |
UL parent Node class value |
Menu_class |
UL Node class value |
menu_id |
UL Node ID value |
Before |
Text before the menu link |
After |
Text after a menu link |
Link_before |
Text in front of each menu link text |
Link_after |
Text after each menu link text |
Depth |
Menu Depth |
WordPress Theme Creation Tutorial 2: navigation menu making