WordPress List Pages Template Tag
The WordPress list pages template tag displays a list of the static pages, such as About Me or Contact, that you can create on your WordPress website. Displaying a link to the static pages with the <?php wp_list_pages(); ?> tag makes them available so that readers can click the links to read the content you’ve provided.
WordPress has a handy custom menu feature that you can use instead of the wp_list_pages(); template tag. Still, you may want to use this tag if you want complete control over how the list of pages appears on your website.
The <list> tag parameters use the string style. The table lists the most common parameters used for the wp_list_pages(); template tag.
In the Possible Values column of the table, values that appear in bold are the default values set by WordPress. Keep this convention in mind for all the parameter values.
|Parameter||Type||Description and Values|
|child_of||Integer||Displays only the subpages of the page (pages with a parent page set in the Page Attributes section of the Edit Page page in your Dashboard); uses the numeric ID for a page as the value. Defaults to 0 (display all pages).|
|sort_column||String||Sorts pages with one of the following options: 'post_title' sorts alphabetically by page title
menu_order' sorts by page order (that is, the order in which pages appear in the Manage tab and Pages subtab of the Dashboard).
'post_date' sorts by the date on which pages were created.
'post_modified' sorts by the time when the page was last modified.
'post_author' sorts by author, according to the author ID #.
'post_name' sorts alphabetically by the post slug.
|exclude||String||Lists the numeric page ID numbers, separated by commas, that you want to exclude from the page list display (for example, 'exclude=10, 20, 30'). There is no default value.|
|depth||Integer||Uses a numeric value for how many levels of pages display in
the list of pages. Possible options:
0 displays all pages, including main and subpages (default).
–1 shows subpages but doesn't indent them in the list display.
1 shows only main pages, no subpages.
|show_date||String||Displays the date when the page was created or last modified. Possible options: ' ' displays no date (default). 'modified' displays the date when the page was last modified. 'created' displays the date when the page was created.|
|date_format||String||Sets the format of the date to be displayed. Defaults to the date format configured in the Options tab and General subtab of the Dashboard.|
|title_li||String||Types text for the heading of the page list. Defaults to display the text: "Pages". If the value is empty (''), no heading displays; for example, 'title_li=My Pages' displays the heading My Pages above the page list.|
Page lists display in an unordered list (or bulleted list). An unordered list is a list with a bullet point in front of every page link.
The following tag and query string displays a list of pages without the text heading Pages. In other words, this tag displays no title at the top of the page’s link list:
<?php wp_list_pages('title_li='); ?>
The following tag and query string displays the list of pages sorted by the date when they were created; the date also displays along with the page name:
<?php wp_list_pages('sort_column=post_date&show_date='created'); ?>
Take a look at the way query-string parameters are written:
The entire string is surrounded by single quotation marks, and there is no white space within the query string. Each parameter is joined to its value by the = character. When you use multiple parameters/values, you separate them with the & character. You can think of the string like this: parameter1=valueANDparameter2=valueANDparameter3=value. Keep this convention in mind for other template tags and parameters.