Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ul><?php
- $page_ids = array();
- foreach( get_pages() as $pages ) {
- if(!$pages->post_parent) $page_ids[] = $pages->ID;
- }
- foreach( $page_ids as $page_id ) :
- $postid = $page_id;
- $args = array(
- 'post_type' => 'page',
- 'post_status' => 'publish',
- 'posts_per_page' => -1,
- 'post_parent' => $postid
- );
- $child_level = get_posts($args);
- if($child_level) :
- foreach($child_level as $child_page) :
- $args = array(
- 'post_type' => 'page',
- 'post_status' => 'publish',
- 'posts_per_page' => -1,
- 'post_parent' => $child_page->ID
- );
- $grandchild_level = get_posts($args);
- if($grandchild_level) :
- foreach($grandchild_level as $grandchild_page) {
- $grandchild_ids[] = $grandchild_page->ID;
- }
- endif;
- endforeach;
- endif;
- endforeach; //ends 'foreach( $page_ids as $page_id ) :'
- $args = array(
- 'post_type' => 'page',
- 'post_status' => 'publish',
- 'posts_per_page' => 2,
- 'orderby' => 'rand',
- 'post__in' => $grandchild_ids
- );
- $my_query = null;
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() ) {
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
- <?php endwhile;
- }
- wp_reset_query();
- ?></ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement