CINXE.COM

Function Reference/wp list pages « WordPress Codex

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head><script type="text/javascript" src="/_static/js/bundle-playback.js?v=HxkREWBo" charset="utf-8"></script> <script type="text/javascript" src="/_static/js/wombat.js?v=txqj7nKC" charset="utf-8"></script> <script>window.RufflePlayer=window.RufflePlayer||{};window.RufflePlayer.config={"autoplay":"on","unmuteOverlay":"hidden"};</script> <script type="text/javascript" src="/_static/js/ruffle/ruffle.js"></script> <script type="text/javascript"> __wm.init("https://web.archive.org/web"); __wm.wombat("http://codex.wordpress.org/Template_Tags/wp_list_pages","20110624081238","https://web.archive.org/","web","/_static/", "1308903158"); </script> <link rel="stylesheet" type="text/css" href="/_static/css/banner-styles.css?v=S1zqJCYt" /> <link rel="stylesheet" type="text/css" href="/_static/css/iconochive.css?v=3PDvdIFv" /> <!-- End Wayback Rewrite JS Include --> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Style-Type" content="text/css"/> <meta name="generator" content="MediaWiki 1.15.5"/> <meta name="keywords" content="Function Reference/wp list pages,Template Tags/wp list pages,Administration Panels,Customizing Your Sidebar,Database Description,Designing Headers,Formatting Date and Time,Function Reference,Function Reference/get pages,Function Reference/wp dropdown categories,Function Reference/wp dropdown pages"/> <link rel="canonical" href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_list_pages"/> <link rel="shortcut icon" href="/web/20110624081238im_/http://codex.wordpress.org/favicon.ico"/> <link rel="search" type="application/opensearchdescription+xml" href="/web/20110624081238/http://codex.wordpress.org/opensearch_desc.php" title="Codex (en)"/> <link rel="alternate" type="application/rss+xml" title="Codex RSS feed" href="/web/20110624081238/http://codex.wordpress.org/index.php?title=Special:RecentChanges&amp;feed=rss"/> <link rel="alternate" type="application/atom+xml" title="Codex Atom feed" href="/web/20110624081238/http://codex.wordpress.org/index.php?title=Special:RecentChanges&amp;feed=atom"/> <title>Function Reference/wp list pages &laquo; WordPress Codex</title> <style type="text/css"> @import url("https://web.archive.org/web/20110624081238cs_/http://s.wordpress.org/style/codex-wp4.css?3"); @import url("https://web.archive.org/web/20110624081238cs_/http://s.wordpress.org/style/wp4.css?10"); </style> <link media="only screen and (max-device-width: 480px)" href="https://web.archive.org/web/20110624081238cs_/http://wordpress.org/style/iphone.css" type="text/css" rel="stylesheet"> <!--[if IE]> <style type="text/css"> @import url("http://wordpress.org/style/ie.css?9"); </style> <![endif]--> <link rel="shortcut icon" href="https://web.archive.org/web/20110624081238im_/http://s.wordpress.org/favicon.ico" type="image/x-icon"/> <script src="https://web.archive.org/web/20110624081238js_/http://www.google-analytics.com/urchin.js" type="text/javascript"></script> <script type="text/javascript"> _uacct = "UA-52447-1"; urchinTracker(); </script> <!--[if IE]> <script type="text/javascript" src="/skins/common/IEFixes.js"></script> <meta http-equiv="imagetoolbar" content="no" /> <![endif]--> <script type="text/javascript" src="/web/20110624081238js_/http://codex.wordpress.org/index.php?title=-&amp;action=raw&amp;gen=js&amp;useskin=codex"></script> <script type="text/javascript">wgBreakFrames=false;wgContentLanguage='en';</script> <script type="text/javascript" src="/web/20110624081238js_/http://codex.wordpress.org/skins/common/wikibits.js"></script> </head> <body id="wordpress-org"> <div id="header"> <div class="wrapper"> <h1><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/" title="WordPress">WordPress.org</a></h1> <form action="https://web.archive.org/web/20110624081238/http://wordpress.org/search/do-search.php" method="get" id="head-search"> <input class="text" name="search" type="text" value="Search the Codex" maxlength="150" onfocus="this.value=(this.value=='Search the Codex') ? '' : this.value;" onblur="this.value=(this.value=='') ? 'Search the Codex' : this.value;"/> <input type="submit" class="button" value="Go"/> </form> <ul> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/" title="Home is where the heart is.">Home</a></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/showcase/" title="See some of the sites built on WordPress.">Showcase</a></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/extend/" title="Taking WordPress beyond your wildest imagination">Extend</a> <ul class="nav-submenu"> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/extend/plugins/" title="Plugins can extend WordPress to do almost anything you can imagine.">Plugins</a></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/extend/themes/" title="Find just the right look for your website.">Themes</a></li> </ul></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/about/" title="About the WordPress Organization, and where we're going.">About</a></li> <li><a class="current" href="https://web.archive.org/web/20110624081238/http://codex.wordpress.org/Main_Page" title="Documentation, tutorials, best practices.">Docs</a></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/development/" title="Come here for the latest scoop.">Blog</a></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/support/" title="Support and discussion forums.">Forums</a></li> <li><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/hosting/" title="Find a home for your blog">Hosting</a></li> <li id="download"><a href="https://web.archive.org/web/20110624081238/http://wordpress.org/download/" title="Get it. Got it? Good.">Download</a></li> </ul> </div> </div> <div id="headline"> <div class="wrapper"> <h2>Codex</h2> <div class="portlet" id="p-personal"> <p class="login">Codex tools: <a href="/web/20110624081238/http://codex.wordpress.org/index.php?title=Special:UserLogin&amp;returnto=Function_Reference/wp_list_pages">Log in</a> </p> </div> </div> </div> <div id="pagebody"> <div class="wrapper"> <div class="col-10" id="bodyContent"> <h2 class="pagetitle">Function Reference/wp list pages</h2> <!-- start content --> <p class="LanguageLinks" style="border:1px solid #CCCCCC; line-height:1.5; text-align:left; color:#333333; font-size:90%; padding:10px;"><span style="white-space:nowrap;"><a href="/web/20110624081238/http://codex.wordpress.org/Multilingual_Codex" title="Multilingual Codex" class="mw-redirect">Languages</a>:</span> <a href="/web/20110624081238/http://codex.wordpress.org/zh-cn:%E6%A8%A1%E6%9D%BF%E6%A0%87%E7%AD%BE/wp_list_pages" title="zh-cn:模板标签/wp list pages">中文(简体)</a> • <a href="/web/20110624081238/http://codex.wordpress.org/Template_Tags/wp_list_pages" title="Template Tags/wp list pages" class="mw-redirect">English</a> • <a href="https://web.archive.org/web/20110624081238/http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/wp_list_pages" class="external text" title="http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/wp_list_pages">日本語</a> • <small>(<a href="/web/20110624081238/http://codex.wordpress.org/Multilingual_Codex#Language_Cross_Reference" title="Multilingual Codex" class="mw-redirect">Add your language</a>)</small> </p> <table id="toc" class="toc" summary="Contents"><tr><td><div id="toctitle"><h2>Contents</h2></div> <ul> <li class="toclevel-1"><a href="#Description"><span class="tocnumber">1</span> <span class="toctext">Description</span></a></li> <li class="toclevel-1"><a href="#Usage"><span class="tocnumber">2</span> <span class="toctext">Usage</span></a> <ul> <li class="toclevel-2"><a href="#Default_Usage"><span class="tocnumber">2.1</span> <span class="toctext">Default Usage</span></a></li> </ul> </li> <li class="toclevel-1"><a href="#Parameters"><span class="tocnumber">3</span> <span class="toctext">Parameters</span></a></li> <li class="toclevel-1"><a href="#Examples"><span class="tocnumber">4</span> <span class="toctext">Examples</span></a> <ul> <li class="toclevel-2"><a href="#Hiding_or_Changing_the_List_Heading"><span class="tocnumber">4.1</span> <span class="toctext">Hiding or Changing the List Heading</span></a></li> <li class="toclevel-2"><a href="#List_Pages_by_Page_Order"><span class="tocnumber">4.2</span> <span class="toctext">List Pages by Page Order</span></a></li> <li class="toclevel-2"><a href="#Sort_Pages_by_Post_Date"><span class="tocnumber">4.3</span> <span class="toctext">Sort Pages by Post Date</span></a></li> <li class="toclevel-2"><a href="#Exclude_Pages_from_List"><span class="tocnumber">4.4</span> <span class="toctext">Exclude Pages from List</span></a></li> <li class="toclevel-2"><a href="#Include_Pages_in_List"><span class="tocnumber">4.5</span> <span class="toctext">Include Pages in List</span></a></li> <li class="toclevel-2"><a href="#List_Sub-Pages"><span class="tocnumber">4.6</span> <span class="toctext">List Sub-Pages</span></a></li> <li class="toclevel-2"><a href="#List_subpages_even_if_on_a_subpage"><span class="tocnumber">4.7</span> <span class="toctext">List subpages even if on a subpage</span></a></li> <li class="toclevel-2"><a href="#List_whole_subpages"><span class="tocnumber">4.8</span> <span class="toctext">List whole subpages</span></a></li> <li class="toclevel-2"><a href="#Markup_and_styling_of_page_items"><span class="tocnumber">4.9</span> <span class="toctext">Markup and styling of page items</span></a></li> <li class="toclevel-2"><a href="#List_parent_Page_and_all_descendant_Pages"><span class="tocnumber">4.10</span> <span class="toctext">List parent Page and all descendant Pages</span></a></li> <li class="toclevel-2"><a href="#List_current_Page.2C_ancestors_of_current_page.2C_and_children_of_current_page"><span class="tocnumber">4.11</span> <span class="toctext">List current Page, ancestors of current page, and children of current page</span></a></li> <li class="toclevel-2"><a href="#List_the_Home_page"><span class="tocnumber">4.12</span> <span class="toctext">List the Home page</span></a></li> <li class="toclevel-2"><a href="#List_members_of_a_custom_post_type"><span class="tocnumber">4.13</span> <span class="toctext">List members of a custom post type</span></a></li> </ul> </li> <li class="toclevel-1"><a href="#Notes"><span class="tocnumber">5</span> <span class="toctext">Notes</span></a></li> <li class="toclevel-1"><a href="#Changelog"><span class="tocnumber">6</span> <span class="toctext">Changelog</span></a></li> <li class="toclevel-1"><a href="#Source_File"><span class="tocnumber">7</span> <span class="toctext">Source File</span></a></li> <li class="toclevel-1"><a href="#Related"><span class="tocnumber">8</span> <span class="toctext">Related</span></a></li> </ul> </td></tr></table><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </script> <a name="Description" id="Description"></a><h2> <span class="mw-headline"> Description </span></h2> <p>Displays a list of WordPress <a href="/web/20110624081238/http://codex.wordpress.org/Pages" title="Pages">Pages</a> as links. It is often used to customize the <a href="/web/20110624081238/http://codex.wordpress.org/Customizing_Your_Sidebar" title="Customizing Your Sidebar">Sidebar</a> or <a href="/web/20110624081238/http://codex.wordpress.org/Designing_Headers" title="Designing Headers">Header</a>, but may be used in other <a href="/web/20110624081238/http://codex.wordpress.org/Templates" title="Templates">Templates</a> as well. </p> <a name="Usage" id="Usage"></a><h2> <span class="mw-headline"> Usage </span></h2> <p><code><span style="color: #000000"> &nbsp;<span style="color: #0000BB">&lt;?php&nbsp;wp_list_pages</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$args&nbsp;</span><span style="color: #007700">);&nbsp;</span><span style="color: #0000BB">?&gt;</span>&nbsp;</span> </code> </p> <a name="Default_Usage" id="Default_Usage"></a><h3> <span class="mw-headline"> Default Usage </span></h3> <pre> &lt;?php $args = array( 'depth' =&gt; 0, 'show_date' =&gt; '', 'date_format' =&gt; get_option('date_format'), 'child_of' =&gt; 0, 'exclude' =&gt; '', 'include' =&gt; '', 'title_li' =&gt; __('Pages'), 'echo' =&gt; 1, 'authors' =&gt; '', 'sort_column' =&gt; 'menu_order, post_title', 'link_before' =&gt; '', 'link_after' =&gt; '', 'walker' =&gt; '' );&nbsp;?&gt; </pre> <p>By default, the usage shows: </p> <ul><li> All Pages and sub-pages are displayed (no depth restriction) </li><li> Date created is not displayed </li><li> Is not restricted to the child_of any Page </li><li> No pages are excluded </li><li> No pages are explicitly included </li><li> The title of the pages listed is "Pages" </li><li> Results are echoed (displayed) </li><li> Is not restricted to any specific author </li><li> Sorted by Page Order then Page Title. </li><li> Sorted in ascending order </li><li> Pages displayed in a hierarchical indented fashion (not shown in defaults above) </li><li> Includes all Pages (not shown in defaults above) </li><li> Not restricted to Pages with specific meta key/meta value (not shown in defaults above) </li><li> No Parent/Child trees excluded </li></ul> <a name="Parameters" id="Parameters"></a><h2> <span class="mw-headline"> Parameters </span></h2> <dl><dt> <b>sort_column</b>&nbsp;</dt><dd> (<i>string</i>) Sorts the list of Pages in a number of different ways. The default setting is <i>sort alphabetically by Page title</i>. <ul><li> <tt>'post_title'</tt> - Sort Pages alphabetically (by title) - default </li><li> <tt>'menu_order'</tt> - Sort Pages by Page Order. Note the difference between <i>Page Order</i> and <i>Page ID</i>. 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 <a href="/web/20110624081238/http://codex.wordpress.org/Pages_Pages_SubPanel" title="Pages Pages SubPanel" class="mw-redirect">Pages→Edit</a> panel. See the <a href="#List_Pages_by_Page_Order" title="">example</a> below. </li><li> <tt>'post_date'</tt> - Sort by creation time. </li><li> <tt>'post_modified'</tt> - Sort by time last modified. </li><li> <tt>'ID'</tt> - Sort by numeric Page ID. </li><li> <tt>'post_author'</tt> - Sort by the Page author's numeric ID. </li><li> <tt>'post_name'</tt> - Sort alphabetically by Post <a href="/web/20110624081238/http://codex.wordpress.org/Glossary#Slug" title="Glossary">slug</a>. </li></ul> </dd><dd><b>Note:</b> The <b>sort_column</b> parameter can be used to sort the list of Pages by the descriptor of any field in the <a href="/web/20110624081238/http://codex.wordpress.org/Database_Description#Table:_wp_posts" title="Database Description">wp_post table</a> of the WordPress database. Some useful examples are listed here. </dd></dl> <dl><dt> <b>sort_order</b>&nbsp;</dt><dd> (<i>string</i>) Change the sort order of the list of Pages (either ascending or descending). The default is <i>ascending</i>. Valid values: <ul><li> <tt>'ASC'</tt> - Sort from lowest to highest (Default). </li><li> <tt>'DESC'</tt> - Sort from highest to lowest. </li></ul> </dd></dl> <dl><dt> <b>exclude</b>&nbsp;</dt><dd> (<i>string</i>) Define a comma-separated list of Page IDs to be excluded from the list (example: <tt>'exclude=3,7,31'</tt>). There is no default value. See the <a href="#Exclude_Pages_from_List" title="">Exclude Pages from List</a> example below. </dd></dl> <dl><dt> <b>exclude_tree</b>&nbsp;</dt><dd> (<i>string</i>) 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 <tt>'exclude_tree=5'</tt> would exclude the parent Page 5, and its child (all descendant) Pages. (This parameter was added with <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.7" title="Version 2.7">Version 2.7</a>, and it does not function as described as of version 2.8.1 - <a href="https://web.archive.org/web/20110624081238/http://core.trac.wordpress.org/ticket/8683" class="external text" title="http://core.trac.wordpress.org/ticket/8683">See bug report</a>.) </dd></dl> <dl><dt> <b>include</b>&nbsp;</dt><dd> (<i>string</i>) Only include certain Pages in the list generated by <i>wp_list_pages</i>. Like <b>exclude</b>, this parameter takes a comma-separated list of Page IDs. There is no default value. See the <a href="#Include_Pages_in_List" title="">Include Pages in List</a> example below. </dd></dl> <dl><dt> <b>depth</b>&nbsp;</dt><dd> (<i>integer</i>) This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by <i>wp_list_pages</i>. The default value is <i>0</i> (display all pages, including all sub-pages). <ul><li> <tt>0</tt> (default) Displays pages at any depth and arranges them hierarchically in nested lists </li><li> <tt>-1</tt> Displays pages at any depth and arranges them in a single, flat list </li><li> <tt>1</tt> Displays top-level Pages only </li><li> <tt>2</tt>, <tt>3</tt> … Displays Pages to the given depth </li></ul> </dd></dl> <dl><dt> <b>child_of</b>&nbsp;</dt><dd> (<i>integer</i>) 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 <i>0</i> (displays all Pages). </dd></dl> <dl><dt> <b>show_date</b>&nbsp;</dt><dd> (<i>string</i>) Display creation or last modified date next to each Page. The default value is the <i>null value</i> (do not display dates). Valid values: <ul><li> <tt>''</tt> - Display no date (Default). </li><li> <tt>'modified'</tt> - Display the date last modified. </li><li> <tt>'xxx'</tt> - Any value other than <i>modified</i> displays the date (<b>post_date</b>) the Page was first created. See the <a href="#Sort_Pages_by_Post_Date" title="">example</a> below. </li></ul> </dd></dl> <dl><dt> <b>date_format</b>&nbsp;</dt><dd> (<i>string</i>) Controls the format of the Page date set by the <b>show_date</b> parameter (example: "<tt>l, F j, Y</tt>"). This parameter defaults to the date format configured in your WordPress options. See <a href="/web/20110624081238/http://codex.wordpress.org/Formatting_Date_and_Time" title="Formatting Date and Time">Formatting Date and Time</a> and the <a href="https://web.archive.org/web/20110624081238/http://php.net/date" class="external text" title="http://php.net/date">date format page on the php web site</a>. </dd></dl> <dl><dt> <b>title_li</b>&nbsp;</dt><dd> (<i>string</i>) Set the text and style of the Page list's heading. Defaults to <tt>'__('Pages')'</tt>, which displays "Pages" (the <tt>__(&#39;&#39;)</tt> is used for <a href="/web/20110624081238/http://codex.wordpress.org/Localization" title="Localization" class="mw-redirect">localization purposes</a>). If passed a null or empty value (<tt>&#39;&#39;</tt>), no heading is displayed, and the list will not be wrapped with <tt>&lt;ul&gt;, &lt;/ul&gt;</tt> tags. See the example for <a href="#Hiding_or_Changing_the_List_Heading" title="">Headings</a>. </dd></dl> <dl><dt> <b>echo</b>&nbsp;</dt><dd> (<i>boolean</i>) 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 <i>1</i> (display the generated list items). Valid values: <ul><li> <tt>1 (True)</tt> - default </li><li> <tt>0 (False)</tt> </li></ul> </dd></dl> <dl><dt> meta_key&nbsp;</dt><dd> (<i>string</i>) Only include the Pages that have this Custom Field Key (use in conjunction with the meta_value field). </dd><dt> meta_value&nbsp;</dt><dd> (<i>string</i>) Only include the Pages that have this Custom Field Value (use in conjunction with the meta_key field). </dd></dl> <dl><dt> <b>link_before</b>&nbsp;</dt><dd> (<i>string</i>) Sets the text or html that precedes the link text inside &lt;a&gt; tag. (This parameter was added with <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.7" title="Version 2.7">Version 2.7</a>) </dd></dl> <dl><dt> <b>link_after</b>&nbsp;</dt><dd> (<i>string</i>) Sets the text or html that follows the link text inside &lt;a&gt; tag. (This parameter was added with <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.7" title="Version 2.7">Version 2.7</a>) </dd></dl> <dl><dt> <b>authors</b>&nbsp;</dt><dd> (<i>string</i>) Only include Pages authored by the authors in this comma-separated list of author IDs. If no authors are specified, all authors are included. </dd></dl> <dl><dt> <b>number</b>&nbsp;</dt><dd> (<i>integer</i>) Sets the number of Pages to display. This causes the SQL LIMIT value to be defined. Default to no LIMIT. (This parameter was added with <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.8" title="Version 2.8">Version 2.8</a>) NOTE: this is currently not working, see <a href="https://web.archive.org/web/20110624081238/http://core.trac.wordpress.org/ticket/10745" class="external free" title="http://core.trac.wordpress.org/ticket/10745">http://core.trac.wordpress.org/ticket/10745</a> </dd></dl> <dl><dt> <b>offset</b>&nbsp;</dt><dd> (<i>integer</i>) The number of Pages to pass over (or displace) before collecting the set of Pages. Default is no OFFSET. (This parameter was added with <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.8" title="Version 2.8">Version 2.8</a>) </dd></dl> <a name="Examples" id="Examples"></a><h2> <span class="mw-headline"> Examples </span></h2> <a name="Hiding_or_Changing_the_List_Heading" id="Hiding_or_Changing_the_List_Heading"></a><h3> <span class="mw-headline"> Hiding or Changing the List Heading </span></h3> <p>The default heading of the list ("Pages") of Pages generated by <i>wp_list_pages</i> can be hidden by passing a null or empty value to the <b>title_li</b> parameter. The following example displays no heading text above the list. </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('title_li=');&nbsp;?&gt; &lt;/ul&gt;</pre> <p>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 <tt>&lt;h2&gt;</tt>: </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('include=5,9,23&amp;title_li=&lt;h2&gt;' . __('Poetry') . '&lt;/h2&gt;' );&nbsp;?&gt; &lt;/ul&gt;</pre> <a name="List_Pages_by_Page_Order" id="List_Pages_by_Page_Order"></a><h3> <span class="mw-headline"> List Pages by Page Order </span></h3> <p>The following example lists the Pages in the order defined by the <b>Order</b> setting for each Page in the <a href="/web/20110624081238/http://codex.wordpress.org/Pages_Pages_SubPanel" title="Pages Pages SubPanel" class="mw-redirect">Pages→Edit</a> panel. </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('sort_column=menu_order');&nbsp;?&gt; &lt;/ul&gt;</pre> <p>If you wanted to sort the list by Page Order and display the word "Prose" as the list heading (in h2 style) on a Sidebar, you could add the following code to the sidebar.php file: </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('sort_column=menu_order&amp;title_li=&lt;h2&gt;' . __('Prose') . '&lt;/h2&gt;' );&nbsp;?&gt; &lt;/ul&gt;</pre> <p>Using the following piece of code, the Pages will display without heading and in <i>Page Order</i>: </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('sort_column=menu_order&amp;title_li=');&nbsp;?&gt; &lt;/ul&gt;</pre> <a name="Sort_Pages_by_Post_Date" id="Sort_Pages_by_Post_Date"></a><h3> <span class="mw-headline"> Sort Pages by Post Date</span></h3> <p>This example displays Pages sorted by (creation) date, and shows the date next to each Page list item. </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('sort_column=post_date&amp;show_date=created');&nbsp;?&gt; &lt;/ul&gt;</pre> <a name="Exclude_Pages_from_List" id="Exclude_Pages_from_List"></a><h3> <span class="mw-headline"> Exclude Pages from List </span></h3> <p>Use the <b>exclude</b> parameter to hide certain Pages from the list to be generated by <i>wp_list_pages</i>. </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('exclude=17,38' );&nbsp;?&gt; &lt;/ul&gt;</pre> <a name="Include_Pages_in_List" id="Include_Pages_in_List"></a><h3> <span class="mw-headline"> Include Pages in List </span></h3> <p>To include only certain Pages in the list, for instance, Pages with ID numbers 35, 7, 26 and 13, use the <b>include</b> parameter. </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('include=7,13,26,35&amp;title_li=&lt;h2&gt;' . __('Pages') . '&lt;/h2&gt;' );&nbsp;?&gt; &lt;/ul&gt; </pre> <a name="List_Sub-Pages" id="List_Sub-Pages"></a><h3> <span class="mw-headline"> List Sub-Pages </span></h3> <p><b>Versions prior to Wordpress 2.0.1&nbsp;:</b> </p><p>Put this inside the <tt>the_post()</tt> section of the page.php template of your WordPress theme after <tt>the_content()</tt>, or put it in a copy of the page.php template that you use for pages that have sub-pages: </p> <pre>&lt;ul&gt; &lt;?php global $id; wp_list_pages(&quot;title_li=&amp;child_of=$id&amp;show_date=modified &amp;date_format=$date_format&quot;);&nbsp;?&gt; &lt;/ul&gt;</pre> <p>This example does not work with Wordpress 2.0.1 or newer if placed in a page template because the global $id is not set. Use the following code instead. </p><p><b>Wordpress 2.0.1 or newer&nbsp;:</b> </p><p>NOTE: Requires an HTML tag (either <tt>&lt;ul&gt;</tt> or <tt>&lt;ol&gt;</tt>) even if there are no subpages. Keep this in mind if you are using css to style the list. </p> <pre>&lt;ul&gt; &lt;?php wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;show_date=modified &amp;date_format=$date_format');&nbsp;?&gt; &lt;/ul&gt; </pre> <p>The following example will generate a list only if there are child (Pages that designate the current page as a Parent) for the current Page: </p> <pre>&lt;?php $children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;echo=0'); if ($children) {&nbsp;?&gt; &lt;ul&gt; &lt;?php echo $children;&nbsp;?&gt; &lt;/ul&gt; &lt;?php }&nbsp;?&gt; </pre> <a name="List_subpages_even_if_on_a_subpage" id="List_subpages_even_if_on_a_subpage"></a><h3> <span class="mw-headline"> List subpages even if on a subpage </span></h3> <p>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. </p><p>This code will not work if placed after a widget block in the sidebar. </p><p><br/> </p> <pre>&lt;?php if($post-&gt;post_parent) $children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$post-&gt;post_parent.&quot;&amp;echo=0&quot;); else $children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$post-&gt;ID.&quot;&amp;echo=0&quot;); if ($children) {&nbsp;?&gt; &lt;ul&gt; &lt;?php echo $children;&nbsp;?&gt; &lt;/ul&gt; &lt;?php }&nbsp;?&gt; </pre> <p>As an alternative, this code in a <i>sidebar.php</i>, displays only top level Pages, but when viewing a Page that has children (or is a child) it displays only children of that parent. </p> <ul><li> When visiting main page, all top level pages are listed in the sidebar. </li><li> When visiting a top level page with no children, all top level pages are listed. </li><li> When visiting a top level page with children, just the children pages, and descendant pages, are listed. </li><li> When visiting a child page, just the children, and descendant pages, of that parent, are listed. </li></ul> <pre> &lt;?php $output = wp_list_pages('echo=0&amp;depth=1&amp;title_li=&lt;h2&gt;Top Level Pages &lt;/h2&gt;' ); if (is_page( )) { $page = $post-&gt;ID; if ($post-&gt;post_parent) { $page = $post-&gt;post_parent; } $children=wp_list_pages( 'echo=0&amp;child_of=' . $page . '&amp;title_li=' ); if ($children) { $output = wp_list_pages ('echo=0&amp;child_of=' . $page . '&amp;title_li=&lt;h2&gt;Child Pages&lt;/h2&gt;'); } } echo $output; ?&gt; </pre> <ul><li>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.) </li></ul> <pre> &lt;?php if($post-&gt;post_parent) { $children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$post-&gt;post_parent.&quot;&amp;echo=0&quot;); $titlenamer = get_the_title($post-&gt;post_parent); } else { $children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$post-&gt;ID.&quot;&amp;echo=0&quot;); $titlenamer = get_the_title($post-&gt;ID); } if ($children) {&nbsp;?&gt; &lt;h2&gt; &lt;?php echo $titlenamer;&nbsp;?&gt; &lt;/h2&gt; &lt;ul&gt; &lt;?php echo $children;&nbsp;?&gt; &lt;/ul&gt; &lt;?php }&nbsp;?&gt; </pre> <a name="List_whole_subpages" id="List_whole_subpages"></a><h3> <span class="mw-headline"> List whole subpages </span></h3> <p>This is how to get the whole subpages list </p> <pre> &lt;?php if(!$post-&gt;post_parent){ // will display the subpages of this top level page $children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$post-&gt;ID.&quot;&amp;echo=0&quot;); }else{ // diplays only the subpages of parent level //$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$post-&gt;post_parent.&quot;&amp;echo=0&quot;); if($post-&gt;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 = end($post-&gt;ancestors); $children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;.$ancestors.&quot;&amp;echo=0&quot;); // you will always get the whole subpages list } } if ($children) {&nbsp;?&gt; &lt;ul&gt; &lt;?php echo $children;&nbsp;?&gt; &lt;/ul&gt; &lt;?php }&nbsp;?&gt; </pre> <a name="Markup_and_styling_of_page_items" id="Markup_and_styling_of_page_items"></a><h3> <span class="mw-headline"> Markup and styling of page items </span></h3> <p>By default, <b>wp_list_pages()</b> generates a nested, unordered list of WordPress <a href="/web/20110624081238/http://codex.wordpress.org/Pages" title="Pages">Pages</a> created with the <a href="/web/20110624081238/http://codex.wordpress.org/Administration_Panels#Write_Page" title="Administration Panels" class="mw-redirect">Write</a> &gt; <a href="/web/20110624081238/http://codex.wordpress.org/Write_Page_SubPanel" title="Write Page SubPanel">Page</a> admin panel. You can remove the outermost item (<tt>li.pagenav</tt>) and list (<tt>ul</tt>) by setting the <var>title_li</var> parameter to an empty string. </p><p>All list items (<tt>li</tt>) generated by <b>wp_list_pages()</b> are marked with the class <tt>page_item</tt>. When <b>wp_list_pages()</b> is called while displaying a Page, the list item for that Page is given the additional class <tt>current_page_item</tt>. </p> <pre>&lt;li class=&quot;pagenav&quot;&gt; Pages [title_li] &lt;ul&gt; &lt;!-- Output starts here if 'title_li' parameter is empty --&gt; &lt;li class=&quot;page-item-2 page_item current_page_ancestor current_page_parent&quot;&gt; [parent of the current Page] &lt;ul&gt; &lt;li class=&quot;page-item-21 page_item current_page_item&quot;&gt; [the current Page] &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class=&quot;page-item-3 page_item&quot;&gt; [another Page] &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt;</pre> <p>They can be styled with <a href="/web/20110624081238/http://codex.wordpress.org/Glossary#CSS" title="Glossary">CSS selectors</a>: </p> <pre>.pagenav { … } /* the outermost list item; contains whole list */ .page-item-2 { … } /* item for Page ID 2 */ .page_item { … } /* any Page item */ .current_page_item { … } /* the current Page */ .current_page_parent { … } /* parent of the current Page */ .current_page_ancestor { … } /* any ancestor of the current Page */ </pre> <p>In order to achieve an accordion menu effect for instance, the following CSS can be used: </p> <pre> .pagenav ul ul, .pagenav .current_page_item ul ul, .pagenav .current_page_ancestor ul ul, .pagenav .current_page_ancestor .current_page_item ul ul, .pagenav .current_page_ancestor .current_page_ancestor ul ul { display: none; } .pagenav .current_page_item ul, .pagenav .current_page_ancestor ul, .pagenav .current_page_ancestor .current_page_item ul, .pagenav .current_page_ancestor .current_page_ancestor ul, .pagenav .current_page_ancestor .current_page_ancestor .current_page_item ul, .pagenav .current_page_ancestor .current_page_ancestor .current_page_ancestor ul { display: block; } </pre> <a name="List_parent_Page_and_all_descendant_Pages" id="List_parent_Page_and_all_descendant_Pages"></a><h3> <span class="mw-headline"> List parent Page and all descendant Pages </span></h3> <p>Since there's no way to tell <a href="/web/20110624081238/http://codex.wordpress.org/Template_Tags/wp_list_pages" title="Template Tags/wp list pages" class="mw-redirect">wp_list_pages</a> to display a particular parent tree (parent and all generations displayes) this example uses <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/get_pages" title="Function Reference/get pages">get_pages</a> to get all the descendants for a parent, then use <a href="/web/20110624081238/http://codex.wordpress.org/Template_Tags/wp_list_pages" title="Template Tags/wp list pages" class="mw-redirect">wp_list_pages</a> to display the 'family tree'. </p> <pre> &lt;?php // use wp_list_pages to display parent and all child pages all generations (a tree with parent) $parent = 93; $args=array( 'child_of' =&gt; $parent ); $pages = get_pages($args); if ($pages) { $pageids = array(); foreach ($pages as $page) { $pageids[]= $page-&gt;ID; } $args=array( 'title_li' =&gt; 'Tree of Parent Page ' . $parent, 'include' =&gt; $parent . ',' . implode(&quot;,&quot;, $pageids) ); wp_list_pages($args); } ?&gt; </pre> <a name="List_current_Page.2C_ancestors_of_current_page.2C_and_children_of_current_page" id="List_current_Page.2C_ancestors_of_current_page.2C_and_children_of_current_page"></a><h3> <span class="mw-headline"> List current Page, ancestors of current page, and children of current page </span></h3> <p>Since child_of displays all children, wpdb is used instead, along with include to not display everything 'and the kitchen sink'. </p> <pre> &lt;?php //if the post has a parent if($post-&gt;post_parent){ //collect ancestor pages $relations = get_post_ancestors($post-&gt;ID); //get child pages $result = $wpdb-&gt;get_results( &quot;SELECT ID FROM wp_posts WHERE post_parent = $post-&gt;ID AND post_type='page'&quot; ); if ($result){ foreach($result as $pageID){ array_push($relations, $pageID-&gt;ID); } } //add current post to pages array_push($relations, $post-&gt;ID); //get comma delimited list of children and parents and self $relations_string = implode(&quot;,&quot;,$relations); //use include to list only the collected pages. $sidelinks = wp_list_pages(&quot;title_li=&amp;echo=0&amp;include=&quot;.$relations_string); }else{ // display only main level and children $sidelinks = wp_list_pages(&quot;title_li=&amp;echo=0&amp;depth=1&amp;child_of=&quot;.$post-&gt;ID); } if ($sidelinks) {&nbsp;?&gt; &lt;h2&gt;&lt;?php the_title();&nbsp;?&gt;&lt;/h2&gt; &lt;ul&gt; &lt;?php//links in &lt;li&gt; tags echo $sidelinks;&nbsp;?&gt; &lt;/ul&gt; &lt;?php }&nbsp;?&gt; </pre> <a name="List_the_Home_page" id="List_the_Home_page"></a><h3> <span class="mw-headline"> List the Home page </span></h3> <p>If you want a link to the blog page as well use <a href="/web/20110624081238/http://codex.wordpress.org/Template_Tags/wp_page_menu" title="Template Tags/wp page menu" class="mw-redirect"> wp_page_menu()</a>. </p> <a name="List_members_of_a_custom_post_type" id="List_members_of_a_custom_post_type"></a><h3> <span class="mw-headline"> List members of a custom post type </span></h3> <p>If a given custom post type is hierarchical in nature, then <strong class="selflink">wp_list_pages()</strong> can be used to list the member of that custom post type. In this example the custom post type Portfolio is listed: </p> <pre> &lt;?php $args = array( 'post_type'=&gt;'portfolio', 'title_li'=&gt; __('Portfolio') ); wp_list_pages( $args ); ?&gt; </pre> <a name="Notes" id="Notes"></a><h2> <span class="mw-headline"> Notes </span></h2> <ul><li> See Also: <a href="/web/20110624081238/http://codex.wordpress.org/Template_Tags/wp_page_menu" title="Template Tags/wp page menu" class="mw-redirect"> wp_page_menu()</a> </li></ul> <a name="Changelog" id="Changelog"></a><h2> <span class="mw-headline"> Changelog </span></h2> <ul><li> Since: 1.5.0 </li><li> <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.7" title="Version 2.7">2.7</a>&nbsp;: Added the <code>link_before</code>, <code>link_after</code> and <code>exclude_tree</code> parameters. </li><li> <a href="/web/20110624081238/http://codex.wordpress.org/Version_2.8" title="Version 2.8">2.8</a>&nbsp;: Added the <code>number</code> and <code>offset</code> parameters. </li></ul> <a name="Source_File" id="Source_File"></a><h2> <span class="mw-headline"> Source File </span></h2> <p><tt>wp_list_pages()</tt> is located in <code><a href="https://web.archive.org/web/20110624081238/http://core.trac.wordpress.org/browser/tags/3.1.3/wp-includes/post-template.php" class="external text" title="http://core.trac.wordpress.org/browser/tags/3.1.3/wp-includes/post-template.php">wp-includes/post-template.php</a></code>. </p> <a name="Related" id="Related"></a><h2> <span class="mw-headline"> Related </span></h2> <p><a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_list_authors" title="Function Reference/wp list authors"> wp_list_authors()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_list_categories" title="Function Reference/wp list categories" class="mw-redirect"> wp_list_categories()</a>, <strong class="selflink"> wp_list_pages()</strong>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_list_bookmarks" title="Function Reference/wp list bookmarks"> wp_list_bookmarks()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_list_comments" title="Function Reference/wp list comments"> wp_list_comments()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_get_archives" title="Function Reference/wp get archives"> wp_get_archives()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_page_menu" title="Function Reference/wp page menu"> wp_page_menu()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_dropdown_pages" title="Function Reference/wp dropdown pages"> wp_dropdown_pages()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_dropdown_categories" title="Function Reference/wp dropdown categories"> wp_dropdown_categories()</a>, <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_dropdown_users" title="Function Reference/wp dropdown users"> wp_dropdown_users()</a> </p> <div 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 <a href="/web/20110624081238/http://codex.wordpress.org/Function_Reference" title="Function Reference">Function Reference</a> and index of <a href="/web/20110624081238/http://codex.wordpress.org/Template_Tags" title="Template Tags">Template Tags</a>.</div> <div style="clear:both; background-color:#EEEEFF; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;">This article is <a href="/web/20110624081238/http://codex.wordpress.org/Category:Copyedits" title="Category:Copyedits" class="mw-redirect">marked</a> as in need of editing. You can <a href="/web/20110624081238/http://codex.wordpress.org/Codex:Contributing" title="Codex:Contributing">help</a> Codex by <b><a href="https://web.archive.org/web/20110624081238/http://codex.wordpress.org/index.php?title=Function_Reference/wp_list_pages&amp;action=edit" class="external text" title="http://codex.wordpress.org/index.php?title=Function_Reference/wp_list_pages&amp;action=edit">editing it</a></b>.</div> <!-- NewPP limit report Preprocessor node count: 184/1000000 Post-expand include size: 3066/2097152 bytes Template argument size: 754/2097152 bytes Expensive parser function count: 0/100 --> <div class="printfooter"> Retrieved from "<a href="https://web.archive.org/web/20110624081238/http://codex.wordpress.org/Function_Reference/wp_list_pages">http://codex.wordpress.org/Function_Reference/wp_list_pages</a>"</div> <div id="catlinks"><div id="catlinks" class="catlinks"><div id="mw-normal-catlinks"><a href="/web/20110624081238/http://codex.wordpress.org/Special:Categories" title="Special:Categories">Categories</a>:&#32;<span dir="ltr"><a href="/web/20110624081238/http://codex.wordpress.org/Category:Template_Tags" title="Category:Template Tags">Template Tags</a></span> | <span dir="ltr"><a href="/web/20110624081238/http://codex.wordpress.org/Category:Copyedit" title="Category:Copyedit">Copyedit</a></span></div></div></div> <!-- end content --> </div> <div class="col-2"> <ul class="submenu"> <li id="n-mainpage"><a href="/web/20110624081238/http://codex.wordpress.org/Main_Page">Home Page</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/WordPress_Lessons">WordPress Lessons</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/Getting_Started_with_WordPress">Getting Started</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/Working_with_WordPress">Working with WordPress</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/Blog_Design_and_Layout">Design and Layout</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/Advanced_Topics">Advanced Topics</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/Troubleshooting">Troubleshooting</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/Developer_Documentation">Developer Docs</a></li> <li><a href="/web/20110624081238/http://codex.wordpress.org/About_WordPress">About WordPress</a></li> </ul> <h3>Codex Resources</h3> <ul class="submenu"> <li id="n-portal"><a href="/web/20110624081238/http://codex.wordpress.org/Codex:Community_Portal">Community portal</a></li> <li id="n-currentevents"><a href="/web/20110624081238/http://codex.wordpress.org/Current_events">Current events</a></li> <li id="n-recentchanges"><a href="/web/20110624081238/http://codex.wordpress.org/Special:RecentChanges">Recent changes</a></li> <li id="n-randompage"><a href="/web/20110624081238/http://codex.wordpress.org/Special:Random">Random page</a></li> <li id="n-help"><a href="/web/20110624081238/http://codex.wordpress.org/Help:Contents">Help</a></li> </ul> </div> </div> </div> <div id="footer"> <div class="wrapper"> <p> <a href="https://web.archive.org/web/20110624081238/http://wordpress.org/about/privacy/">Privacy</a> | <a href="https://web.archive.org/web/20110624081238/http://wordpress.org/about/gpl/">License / GPL</a> &nbsp; &nbsp; See also: <a href="https://web.archive.org/web/20110624081238/http://wordpress.com/" title="Hassle-free WP hosting">WordPress.com</a> | <a href="https://web.archive.org/web/20110624081238/http://wordpress.tv/" title="Videos, tutorials, WordCamps">WordPress.TV</a> | <a href="https://web.archive.org/web/20110624081238/http://central.wordcamp.org/" title="Find a WordPress event near your home">WordCamp</a> | <a href="https://web.archive.org/web/20110624081238/http://jobs.wordpress.net/" title="Find or post WordPress jobs">WP Jobs</a> | <a href="https://web.archive.org/web/20110624081238/http://ma.tt/" title="Co-founder of WordPress, an example of what WordPress can do">Matt</a> | <a href="https://web.archive.org/web/20110624081238/http://www.facebook.com/WordPress">Fan WP on Facebook</a> | <a href="https://web.archive.org/web/20110624081238/http://wordpress.org/news/feed/" class="rsslink">Blog RSS</a> </p> <h6>Code is Poetry</h6> </div> </div> </body> </html> <!-- user: NULL --> <!-- FILE ARCHIVED ON 08:12:38 Jun 24, 2011 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 03:30:08 Nov 27, 2024. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). --> <!-- playback timings (ms): captures_list: 0.543 exclusion.robots: 0.027 exclusion.robots.policy: 0.016 esindex: 0.011 cdx.remote: 14.171 LoadShardBlock: 84.416 (3) PetaboxLoader3.datanode: 128.001 (4) load_resource: 110.096 PetaboxLoader3.resolve: 62.752 -->

Pages: 1 2 3 4 5 6 7 8 9 10