开发者

retrieve only sub-pages

开发者 https://www.devze.com 2022-12-29 22:35 出处:网络
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, \'par

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

    function about_menu(){
    if (is_page开发者_JAVA技巧('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


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 ); ?>


try adding

global $post;

right before you declare $pages.


$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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号