Advertisement
alchymyth

show all grandchild level pages of the site

Apr 12th, 2011
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <ul><?php
  2. $page_ids = array();
  3.   foreach( get_pages() as $pages ) {
  4.   if(!$pages->post_parent) $page_ids[] = $pages->ID;
  5.   }
  6. foreach( $page_ids as $page_id ) :
  7.  
  8. $postid = $page_id;
  9. $args = array(
  10. 'post_type' => 'page',
  11. 'post_status' => 'publish',
  12. 'posts_per_page' => -1,
  13. 'post_parent' => $postid
  14. );
  15. $child_level = get_posts($args);
  16. if($child_level) :
  17. foreach($child_level as $child_page) :
  18.  
  19. $args = array(
  20. 'post_type' => 'page',
  21. 'post_status' => 'publish',
  22. 'posts_per_page' => -1,
  23. 'post_parent' => $child_page->ID
  24. );
  25. $my_query = null;
  26. $my_query = new WP_Query($args);
  27. if( $my_query->have_posts() ) {
  28. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  29. <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
  30. <?php endwhile;
  31. }
  32. wp_reset_query();
  33.  
  34. endforeach;
  35. endif;
  36.  
  37. endforeach; //ends 'foreach( $page_ids as $page_id ) :'
  38.  
  39. ?></ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement