Load parent pages when there are no child pages

possible code:

<?php                  
$children = wp_list_pages('title_li=&child_of=".$post->ID."&echo=0&depth=1');                   
    if ($children) { ?>                   
        <ul id="three-menu">                   
        <?php echo $children; ?>                   
        </ul>                   
    <?php } //ends (if($children)//
    elseif($post->post_parent) { //if no children, try to get parent page and show siblings pages including the page itself
    $siblings = wp_list_pages('title_li=&child_of=".$post->post_parent."&echo=0&depth=1');                  
        if ($siblings) { ?>                   
            <ul id="three-menu">                   
            <?php echo $siblings; ?>                   
            </ul> 
        <?php } //ends if($siblings)// ?>                  
    <?php } else { //optional: if no children and if no parent, then show all top level pages
    $pagelist = wp_list_pages('title_li=&echo=0&depth=1');                   
        if ($pagelist) { ?>                   
            <ul id="three-menu">                   
            <?php echo $pagelist; ?>                   
            </ul>
        <?php } //ends if($pagelist)// ?>
    <?php } ?>  

contains a lot of redundant coding to keep the structure recognizable simple.

Leave a Comment