retrieve only sub-pages

I want to list all sub-pages only one level though of one particular page. I was reading Function Reference/get pages and thought that $pages = get_pages( array( 'child_of' => $post->ID, 'parent' => $post->ID)) ; will do the trick but it is not working. It lists all pages on the same level like the page I call that code from. If I omit parent option I will get all pages even with sub-pages that I want. But I want only sub-pages.

The whole function is like

Read More
    function about_menu(){
    if (is_page('about')){

    $pages = get_pages( array( 'child_of' => $post->ID, 'parent' => $post->ID)) ;
        foreach($pages as $page)
        {       
        ?>
            <h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
        <?php
        }   
    }
    }

below are screen shots from wp admin and results. Mine is second one

Screen shot from WP admin http://img687.imageshack.us/img687/6139/e2568e8ec2684e7aa1bb3d1.png and the result http://img269.imageshack.us/img269/2365/329c5097c78f4d3186a177c.png

Related posts

Leave a Reply

3 comments

  1. Check out wp_list_pages(). I think these settings will give you what you want.

    <?php
    $args = array(
        'child_of'     => $post->ID, // current page
        'depth'        => 1, // get children only, not grandchildren
        'echo'         => 1, // print immediately when we call wp_list_pages
        'sort_column'  => 'menu_order', // sort by the menu_order parameter
    );      
    ?>
    <?php wp_list_pages( $args ); ?>
    
  2. $paginas = array();
    $paginas_obj = get_pages('sort_column=post_parent,menu_order');
    $paginas['false'] = "Seleciona pagina";
      foreach ($paginas_obj as $pagina) {
      $paginas[$pagina->ID] = $pagina->post_title;
    }