Function Reference/wp page menu
- 1 Description
- 2 Usage
- 3 Parameters
- 4 Return Values
- 5 Examples
- 6 Menu Item CSS Classes
- 7 Notes
- 8 Change Log
- 9 Source File
- 10 Template Description
- 11 Related
- 12 Description
- 13 Usage
- 14 Result
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.
%%% <?php wp_page_menu( $args ); ?> %%%
<?php $args = array( 'depth' => 0, 'sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'include' => '', 'exclude' => '', 'echo' => true, 'show_home' => false, 'link_before' => '', 'link_after' => '' ); ?>
By default, the usage shows:
- All Pages and sub-pages are displayed (no depth restriction)
- Sorted by menu order and title
- The div class is 'menu'
- No pages are excluded
- No pages are explicitly included
- 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
- (integer) This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).
- 0 (default) Displays pages at any depth and arranges them hierarchically in nested lists
- -1 Displays pages at any depth and arranges them in a single, flat list
- 1 Displays top-level Pages only
- 2, 3 … Displays Pages to the given depth
- (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.
- (string) The div class the list is displayed in. Defaults to menu.
- (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
- (string) Define a comma-separated list of Page IDs to be excluded from the list (example: 'exclude=3,7,31'). There is no default value. See the Exclude Pages from List example below.
- (string) Define a comma-separated list of parent Page IDs to be excluded. Use this parameter to exclude a parent and all of that parent's child Pages. So 'exclude_tree=5' would exclude the parent Page 5, and its child (all descendant) Pages. (This parameter was added with Version 2.7, and it does not function as described as of version 2.8.1 - See bug report.)
- (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 1 (Display the generated list items). Valid values:
- 0 (False)
- 1 (True) - default
- (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)
- (string) Sets the text or html that precedes the link text inside <a> tag.
- (string) Sets the text or html that follows the link text inside <a> tag.
- The Menu's HTML, if the 'echo' parameter is set to false.
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=9999' 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'); ?>
Menu Item CSS Classes
The following classes are applied to menu items, i.e. to the HTML <li> tags, generated by wp_page_menu():
All Menu Items
This class is added to menu items that correspond to a static page.
This class is added to menu items that correspond to a static page, where $ID is the static page ID.
Current-Page Menu Items
This class is added to menu items that correspond to the currently rendered static page.
Current-Page Parent Menu Items
This class is added to menu items that correspond to the hierarchical parent of the currently rendered static page.
Current-Page Ancestor Menu Items
This class is added to menu items that correspond to a hierarchical ancestor of the currently rendered static page.
- See Also: wp_list_pages()
- Since: 2.7.0
- 2.8.1 :
sort_columnparameter default changed from '
post_title' to '
wp_page_menu() is located in onlyincludecodewp-includes/post-template.php/code/onlyinclude
div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9
Link to the source code on http://core.trac.wordpress.org/browser/.
- (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.
Link to the stable version: pre检查到模板循环：模板:Trac/pre
Link to trunk: pre检查到模板循环：模板:Trac/pre
includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude
This Template is used by Codex:Template Messages.
pre 检查到模板循环：模板:Message /pre