Template Tags/wp page menu
Материал из WordPress Wiki
Содержание |
Description
The Template Tag, wp_page_menu(), acting as a wrapper for wp_list_pages(), displays a list of WordPress Pages as links. It is useful to customize the Sidebar or Header, but may be used in other Templates as well.
This Template Tag is available for WordPress versions 2.7 and newer.
Usage
%%% <?php wp_page_menu('arguments'); ?> %%%
Examples
Default Usage
$defaults = array(
'title_li' => '',
'sort_column' => 'menu_order',
'menu_class' => 'menu'
'echo' => false);
By default, the usage shows:
- The title of the pages is empty
- Sorted by Page Order
- The div id is 'menu'
- Results are NOT echoed ( NOT displayed)
- Do not add "Home" to the list of pages (this is not shown in defaults above)
- Note: Output is encompassed by the <ul> and </ul> tags
wp_page_menu();
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 are listed under the title, "Page Menu", and Page IDs 5, 9, and 23, are excluded from the list of Pages displayed.
<?php wp_page_menu('show_home=1&exclude=5,9,23&title_li=<h2>' . __('Page Menu') . '</h2>'); ?>
Parameters
In addtion to the parameters listed below, because wp_page_menu() acts as a wrapper for wp_list_pages(), all of the wp_list_pages() parameters can be used with this Template Tag.
- title_li (string)
- Set the text and style of the Page list's heading. Defaults to '__('Pages')', which displays "Pages" (the __('') is used for localization purposes). If passed a null or empty value (''), no heading is displayed, and the list will not be wrapped with <ul>, </ul> tags. See the example for Headings.
- sort_column (string)
- Sorts the list of Pages in a number of different ways. The default setting is sort alphabetically by Page Order (menu_order). 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.
- 'menu_order' - Sort Pages by Page Order. N.B. 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 Write>Pages administrative panel. See the example below. - default
- 'post_title' - Sort Pages alphabetically (by title) - default
- '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.
- title_li (string)
- Set the text and style of the Page list's heading. Defaults to '__('Pages')', which displays "Pages" (the __('') is used for localization purposes). If passed a null or empty value (''), no heading is displayed, and the list will not be wrapped with <ul>, </ul> tags. See the example for Headings.
- 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) - default
- 1 (true)
- 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)