Codex

Template Tags/wp page menu

Contents

Description

Displays a list of WordPress Pages as links, and affords the opportunity to have Home added automatically to the list of Pages displayed. This Tag is useful to customize the Sidebar or Header, but may be used in other Templates as well.

Usage

 <?php wp_page_menu$args ); ?> 

Default Usage

 <?php $args = array(
    
'sort_column' => 'menu_order, post_title',
    
'menu_class'  => 'menu',
    
'include'     => ,
    
'echo'        => true,
    
'show_home'   => false,
    
'link_before' => 
,
    
'link_after'  =>  ); ?>

By default, the usage shows:

  • Sorted by menu order and title
  • The div class is 'menu'
  • Results are echoed (displayed)
  • No link_before or link_after text
  • Do not add "Home" to the list of pages
  • Note: Output is encompassed by the <ul> and </ul> tags

Parameters

sort_column 
(string) Sorts the list of Pages in a alphabetic order by title of the pages. The default setting is sort by menu order and alphabetically by page title. The sort_column parameter can be used to sort the list of Pages by the descriptor of any field in the wp_post table of the WordPress database. Some useful examples are listed here.
  • 'post_title' - Sort Pages alphabetically by title.
  • 'menu_order' - Sort Pages by Page Order. Note the difference between Page Order and Page ID. The Page ID is a unique number assigned by WordPress to every post or page. The Page Order can be set by the user in the administrative panel (e.g. Administration > Page > Edit).
  • 'post_date' - Sort by creation time.
  • 'post_modified' - Sort by time last modified.
  • 'ID' - Sort by numeric Page ID.
  • 'post_author' - Sort by the Page author's numeric ID.
  • 'post_name' - Sort alphabetically by Post slug.
menu_class 
(string) The div class the list is displayed in. Defaults to menu.
include 
(string) Only list pages identified with the corresponding id's, i.e. wp_page_menu('include=2,14') will list only pages with id's 2 and 14
echo 
(boolean) Toggles the display of the generated list of links or return the list as an HTML text string to be used in PHP. The default value is 0 (do NOT display the generated list items). Valid values:
  • 0 (False)
  • 1 (True) - default
show_home 
(boolean) Add "Home" as the first item in the list of "Pages". The URL assigned to "Home" is pulled from the Blog address (URL) in Administration > Settings > General. The default value is 0 (do NOT display "Home" in the generated list). Valid values:
  • 0 (False) - default
  • 1 (True)
  • <any text> - Use this text as the link in place of "Home" (show_home is still considered true)
link_before 
(string) Sets the text or html that proceeds the link text inside <a> tag.
link_after 
(string) Sets the text or html that follows the link text inside <a> tag.

Examples

Display Home as a Page

The following example causes "Home" to be added to the beginning of the list of Pages displayed. In addition, the Pages wrapped in a div element, Page IDs 5, 9, and 23, are excluded from the list of Pages displayed, and the pages are listed in Page Order. The list is prefaced with the title, "Page Menu",

<h2>Page Menu</h2>
<?php wp_page_menu('show_home=1&exclude=5,9,23&menu_class=page-navi&sort_column=menu_order'); ?>

Display Home as a Page called Blog

The following example causes "Blog" (instead of "Home") to be added to the beginning of the list of Pages displayed:

<?php wp_page_menu( array( 'show_home' => 'Blog', 'sort_column' => 'menu_order' ) ); ?>

Display only Home

The following example displays just a link to "Home". Note that the include=99999' references a Page ID that does not exist so only a link for Home is displayed.

<?php wp_page_menu('show_home=1&include=9999'); ?>

Notes

Change Log

Since: 2.7.0

Source File

wp_page_menu() is located in wp-includes/post-template.php.

Related

wp_list_authors, wp_list_categories, wp_list_pages, wp_list_bookmarks, wp_list_comments, wp_get_archives, wp_page_menu, wp_dropdown_pages, wp_dropdown_categories, wp_dropdown_users

See also index of Function Reference and index of Template Tags.