Are you using WordPress as a CMS and want to know How to List WordPress Subpages using wp_list_page().
wp_list_page() is an important function nicely implemented in the newer versions of WordPress as WP becomes a more mature CMS. Creating Subpages (also called childpages and grand childpages) is one nice feature which you can use to really extend the functionality of WP as a CMS. Now let’s say you want to display all the childpages of a particular parent page while viewing the parent page or one of the other childpages, then you can use the following trick.
Here are the steps:
- Create a DIV element in your stylesheet.css like this one: #subpageslistings { float:left; display:inline; margin:55px 0 0 -10px; color:#777; }
- Now insert the following code, wherever you want these links to appear (header, main page content area or sidebar?)<div id=”subpageslistings”>
<?php
$output = wp_list_pages(‘echo=0&depth=1&title_li=<h4> Other Links </h4>’ );
if (is_page( )) {
$page = $post->ID;
if ($post->post_parent) {
$page = $post->post_parent;
}
$children=wp_list_pages( ‘echo=0&child_of=’ . $page . ‘&title_li=’ );
if ($children) {
$output = wp_list_pages (‘echo=0&child_of=’ . $page . ‘&title_li=<h4>Other Links</h4>’);
}
}
echo $output;
?>
</div> - Now spice it up with some CSS styling and let it look the way you want!
Hope this helps.