Skip to main content
added 459 characters in body
Source Link
meekbot
  • 161
  • 2

It would probably be better to do a check first with the function, then generate the list using the current post id.

<?php     
    if ($post->post_parent) { //We Postare IDa notchild, theprint sameout sosub itmenu
 has children          wp_list_pages( array('title_li'=>'','include'=>$post->post_parent) );
<?php if           wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->post_parent) );
    }

//We are not a child but do we have children
$children = wp_list_pages(array('child_of' => $post->ID, !='echo' get_post_top_ancestor_id=> 0));

if ( !empty($children) ) { 
 ?>   //If so print out the sub menu
   <?php wp_list_pages( array('title_li'=>'','include'=>$post->ID) ); ?>
   <?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->ID) );
} ?>
<?php//Not }a child and not a parent so show nothing and continue 
?>

I tested this and it works as you mentioned, I couldn't figure out that function however maybe someone can post a better solution using that function.

It would probably be better to do a check first with the function, then generate the list using the current post id.

// Post ID not the same so it has children    
<?php if ($post->ID != get_post_top_ancestor_id()) { ?>
   <?php wp_list_pages( array('title_li'=>'','include'=>$post->ID) ); ?>
   <?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->ID) ); ?>
<?php } ?>
<?php     
    if ($post->post_parent) { //We are a child, print out sub menu
            wp_list_pages( array('title_li'=>'','include'=>$post->post_parent) );
            wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->post_parent) );
    }

//We are not a child but do we have children
$children = wp_list_pages(array('child_of' => $post->ID, 'echo' => 0));

if ( !empty($children) ) { 
    //If so print out the sub menu
    wp_list_pages( array('title_li'=>'','include'=>$post->ID) );
    wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->ID) );
} 
//Not a child and not a parent so show nothing and continue 
?>

I tested this and it works as you mentioned, I couldn't figure out that function however maybe someone can post a better solution using that function.

Source Link
meekbot
  • 161
  • 2

It would probably be better to do a check first with the function, then generate the list using the current post id.

// Post ID not the same so it has children    
<?php if ($post->ID != get_post_top_ancestor_id()) { ?>
   <?php wp_list_pages( array('title_li'=>'','include'=>$post->ID) ); ?>
   <?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->ID) ); ?>
<?php } ?>