Параметри

(string) Sorts the list of Pages in a number of different ways. The default setting is sort alphabetically by Page title.

'post_title' - Sort Pages alphabetically (by title) - default

'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 Pages→Edit panel. See the example below.

Note: 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.

sort_order

(string) Change the sort order of the list of Pages (either ascending or descending). The default is ascending. Valid values:

'ASC' - Sort from lowest to highest (Default).

'DESC' - Sort from highest to lowest.

exclude

(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.

exclude_tree

(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.)

include

(string) Only include certain Pages in the list generated by wp_list_pages. Like exclude, this parameter takes a comma-separated list of Page IDs. There is no default value. See the Include Pages in List example below.

depth

(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

child_of

(integer) Displays the sub-pages of a single Page only; uses the ID for a Page as the value. Note that the child_of parameter will also fetch "grandchildren" of the given ID, not just direct descendants. Defaults to 0 (displays all Pages).

show_date

(string) Display creation or last modified date next to each Page. The default value is the null value (do not display dates). Valid values:

'' - Display no date (Default).

'modified' - Display the date last modified.

'xxx' - Any value other than modified displays the date (post_date) the Page was first created. See the example below.

(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 1 (display the generated list items). Valid values:

1 (True) - default

0 (False)

meta_key

(string) Only include the Pages that have this Custom Field Key (use in conjunction with the meta_value field).

meta_value

(string) Only include the Pages that have this Custom Field Value (use in conjunction with the meta_key field).

link_before

(string) Sets the text or html that precedes the link text inside <a> tag. (This parameter was added with Version 2.7)

link_after

(string) Sets the text or html that follows the link text inside <a> tag. (This parameter was added with Version 2.7)

authors

(string) Only include Pages authored by the authors in this comma-separated list of author IDs. If no authors are specified, all authors are included.

a comma-separated list of all post status types to return. For example: 'publish,private'

Приклади

Приховування або зміна заголовка списку

The default heading of the list ("Pages") of Pages generated by wp_list_pages can be hidden by passing a null or empty value to the title_li parameter. The following example displays no heading text above the list.

<ul>
<?php wp_list_pages('title_li='); ?>
</ul>

In the following example, only Pages with IDs 9, 5, and 23 are included in the list and the heading text has been changed to the word "Poetry", with a heading style of <h2>:

List subpages even if on a subpage

The above examples will only show the children from the parent page, but not when actually on a child page. This code will show the child pages, and only the child pages, when on a parent or on one of the children.

This code will not work if placed after a widget block in the sidebar.

Page List that: Only displays if child (sub) pages exist, displays page list of subpages on the parent page AND on the child pages HOWEVER this code keeps the parent page name in the title which makes it different from the previous example.)

List whole subpages

This is how to get the whole subpages list

<?php
if(!$post->post_parent){
// will display the subpages of this top level page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
}
else{
if($post->ancestors) {
// now you can get the the top ID of this page
// wp is putting the ids DESC, thats why the top level ID is the last one
$ancestors = get_post_ancestors($this_page);
$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
}
}
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>

List parent Page and all descendant Pages

Since there's no way to tell wp_list_pages to display a particular parent tree (parent and all generations displayes) this example uses get_pages to get all the descendants for a parent, then use wp_list_pages to display the 'family tree'.

List current Page with its ancestors and children

This example will list current Page, ancestors of current page, and children of current page,
Since child_of displays all children, wpdb is used instead, along with include to not display everything 'and the kitchen sink'.

Markup and styling of page items

By default, wp_list_pages() generates a nested, unordered list of WordPress Pages created with the Write > Page admin panel. You can remove the outermost item (li.pagenav) and list (ul) by setting the title_li parameter to an empty string.

All list items (li) generated by wp_list_pages() are marked with the class page_item. When wp_list_pages() is called while displaying a Page, the list item for that Page is given the additional class current_page_item.