Upgrade wp_list_pages() to wp_nav_menu()
in Functions
as how-to, WordPress, wp_list_pages, wp_nav_menu
Following in the series dealing with upgrading to the wp_nav_menu() function in WordPress 3.0 from menus derived from the template tags: wp_page_menu(); wp_list_pages(); and, wp_list_categories(). This post will be covering the options involved in updating to wp_nav_menu() from wp_list_pages().
Like the last post in the series we will look at the default arguments used by each function, starting with wp_nav_menu() 1:
wp_nav_menu( array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => '',
'theme_location' => ''
) );
The following is a default “menu” version of wp_list_pages() 2, 3, often wrapped within a <ul class=”menu”> tag:
<ul class="menu">
<?php wp_list_pages( array(
'sort_column' => 'menu_order, post_title',
'include' => '',
'exclude' => '',
'exclude_tree' => '',
'child_of' => 0,
'show_date' => '',
'date_format' => get_option('date_format'),
'title_li' => __(''),
/* 'title_li' set to '' for menus from the default 'Pages' */
'authors' => '',
'echo' => 1,
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => ''
) ); ?>
</ul>
Here is the break-down of the wp_list_pages() default options from above:
'sort_column'– not used'include'– not used'exclude'– not used'exclude_tree'– not used'child_of'– not used'show_date'– not used'date_format'– not used'title_li'– not used, see below for additional notes'authors'– not used'echo'– similar to wp_nav_menu(); true versus 1 as value'link_before'– same as wp_nav_menu()'link_after'– same as wp_nav_menu()'depth'– same as wp_nav_menu()'walker'– same as wp_nav_menu()
Similar to wp_page_menu(), the ‘sort_column’, ‘include’, ‘exclude’, ‘exclude_tree’, and ‘child_of’ are replaced via the end-user’s specific choices. The ‘show_date’ and its related ‘date_format’ option, as well as the ‘author’ argument, are not available within the default wp_nav_menu() structure. Once again, the balance of the default options in wp_list_pages() matches the defaults found in wp_nav_menu().
Also consider setting the wp_nav_menu() fallback_cb option to 'fallback_cb' => 'wp_list_pages'. This backward compatibility may also be addressed with a custom function as posted by Nicolas Kuttler.
Note: If the 'title_li' => __('') option was being used it may also require the removal of the wrapping <ul> tag in the existing menu structure created with wp_list_pages().
- Share this:
- Share




[...] All of these changes were based on the article I wrote at WPFirstAid.com titled: Upgrade wp_list_pages() to wp_nav_menu(). [...]