Advertisement
alchymyth

5 random pages on grandchild page level

Apr 12th, 2011
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <ul>
  2. <?php $all = get_pages();
  3. foreach($all as $all) {
  4.  if($all->post_parent) {
  5.   if( get_page($all->post_parent)->post_parent ) {
  6.    $tp = get_page($all->post_parent);
  7.    if( !get_page( $tp->post_parent )->post_parent) { $grandchild_ids[] = $all->ID; }
  8.   }
  9.  }
  10. }
  11.  
  12. $args = array(
  13. 'post_type' => 'page',
  14. 'post_status' => 'publish',
  15. 'posts_per_page' => 5,
  16. 'orderby' => 'rand',
  17. 'post__in' => $grandchild_ids
  18. );
  19. $my_query = null;
  20. $my_query = new WP_Query($args);
  21. if( $my_query->have_posts() ) {
  22. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  23. <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
  24. <?php endwhile;
  25. }
  26. wp_reset_query(); ?>
  27. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement