• I’d like to get page list from the bottom level to the 2nd level, NO TOP LEVEL.

    echo $ancestors = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0&depth=3");

    am close to the result, but my output from last level to TOP level. how can minus one level to the 2nd ?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could first get an array of post_ids for the top-level pages like so:

    $exclusion_args = array(
    	'post_type' => 'page',
    	'post_parent' => 0,  // only exclude top level
    	'fields'=>'ids', // only need the ids
    );
    
    $exclusion_query = new WP_Query($exclusion_args);
    $exclusion_ids = $exclusion_query->posts;
    $exclusion_ids_string = implode(',',$exclusion_ids);

    And then you could pass the exclusion ids like so
    wp_list_pages("title_li=&child_of=".$ancestors."&echo=0&depth=3&exclude=".$exclusion_ids_string);

    Hope it helps.

    Thread Starter obgaoml

    (@obgaoml)

    @roccotripaldi thanks a lot. that works
    However, when I change to another page, it doesn’t show relative page’s child pages

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wordpress ancestors’ is closed to new replies.