<?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 } ?>