Custom Navigation

By default, the class on the surrounding <div> tag will be "menu", but you can change this in the function parameters. In fact, you can change the <div> tag to something else entirely, as shown in Listing 6-25.

Listing6-25. Using the wp_nav_menu function

<?php wp_nav_menu( 'sort_column=menu_order&format=ul&menu_class=nav' ); ?>

Because wp_nav_menu() is a new feature, there are several fallback functions that will be used when the user has not yet created a menu, or when a theme that includes wp_nav_menu() is installed on an older version of WordPress. If wp_nav_menu() is called but there are no menus defined, wp_page_menu() is substituted. If you would prefer another substitute, such as wp_list_categories, you can add the name of your preferred function using the fallback_cb() parameter, as shown in Listing 6-26.

Listing 6-26. Changing the wp_nav_menu fallback function

<?php wp_nav_menu( 'sort_column=menu_order&fallback_cb=wp_list_categories' ); ?>

0 0

Post a comment