/ Published in: PHP
This code will list all children pages from a parent page. This method is useful when you don\\\'t want to list all parent pages when you are on a parent page that have no children pages.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php global $post; $thispage = $post->ID; // grabs the current post id from global and then assigns it to $thispage $subpages = get_pages("child_of=".$thispage."&sort_column=menu_order"); // gets a list of pages that are sub pages of $thispage and assigns it to $pagekids ?> <?php if ($subpages) { // if there are any values stored in $pagekids, meaning there are sub-pages of the current page ?> <ul class="links"> <?php wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display ONLY the sub pages of the current page ?> </ul> <?php } else { // $pagekids is empty ?> <ul class="links"> <?php wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&sort_column=menu_order'); // display the sub-pages of the current parent page ?> </ul> <?php } ?>