WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

OK I'm doing a a menu (sidebar menu) that will display this all child pages of parent page (currently open)
|-Child 1
|-Child 2
|Child 3

but in same time when someone is in bolded page (child) will see the same thing
|-Child 1
_|-Child 1
_ _|-Child 2
_ _|- Child 3
|-Child 2
|-Child 3

currently I use next code which do first job well but not the second one with child of child I tried several things but nothing worked

 <?php if ( is_page() ) { 
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&sort_column=post_date&sort_order=DESC'); else
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&sort_column=post_date&sort_order=DESC');
if ($children) { ?> .......

Thanks in advance


As Simon answered it worked but not for all cases and I edited so now final code is:

<?php if ( is_page() ) {
    $stats = count($post->ancestors);
  if($stats == 2){
    $children = wp_list_pages('title_li=&child_of='.get_post( $post->post_parent )->post_parent.'&echo=0&sort_column=post_date&sort_order=DESC&depth=1'); 
    $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&sort_column=post_date&sort_order=DESC&depth=1');
  $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&sort_column=post_date&sort_order=DESC&depth=1');
if ($children) { ?> ....

That's in case if somebody else need this stuff, Cheers and thanks for fast help

share|improve this question
I'm not sure what you need to display ? Siblings to the viewed page or siblings of the parent page ? – Simon Jan 30 '13 at 13:42
I want to see first structure even when someone is on bold child page (in page of child of overall parent – Aleksandar Savic Jan 30 '13 at 19:21
up vote 0 down vote accepted

Could you try this ? The idea is if there is a parent, we should list pages for the parent of this parent.

<?php if ( is_page() ) { 

    if($post->post_parent) {
        $children = wp_list_pages('title_li=&child_of='. get_post( $post->post_parent )->post_parent .'&echo=0&sort_column=post_date&sort_order=DESC'); 
    } else {
        $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&sort_column=post_date&sort_order=DESC');

Other solution would be to try to use depth option which according to codex could list only top-level pages :

<?php if ( is_page() ) { 

    if( $post->post_parent ) {
        $children = wp_list_pages('title_li=&depth=1&echo=0&sort_column=post_date&sort_order=DESC'); 
    } else {
        $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&sort_column=post_date&sort_order=DESC');

Sorry, I don't have time to try the code, but let us know if this is helps (or not).

share|improve this answer

Hope this will get you going!

          $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
          if ($children) { ?>
          <?php echo $children; ?> 
          <?php } ?>

That will get you the child of the current page/template that is set in wp-admin.

share|improve this answer
yes I know that but it's displaying child what I want to find how to get a children from grand parent, so what I logically need to find out is get parent of current page (which I know to do) and from that parent page I want to find his parent (which I don't know how) and if there is a parent (last one) then display his children (sorry for bad english) – Aleksandar Savic Jan 30 '13 at 19:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.