Advertisement
Guest User

Trouble with multiple loops and do_not_duplicate

a guest
Apr 4th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <?php get_header(); ?>
  2.  
  3. <h1>Loop 1</h1>
  4. <?php $do_not_duplicate = array();
  5. $my_query = new WP_Query(array('posts_per_page' => 1, 'post__not_in' => get_option( 'sticky_posts' ) ) );
  6. while ($my_query->have_posts()) : $my_query->the_post();
  7. $do_not_duplicate[]  = $post->ID; ?>
  8. <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
  9. <?php endwhile; ?>
  10. <?php wp_reset_query(); ?>
  11.  
  12.  
  13. <h1>Loop 2</h1>
  14. <?php
  15.  $args=array(
  16.       'posts_per_page' => 1,
  17.       'post__not_in' => $do_not_duplicate,
  18.       'category__in' => array($category->term_id)
  19. );
  20. $my_query = new WP_Query( $args );
  21. while ($my_query->have_posts()) : $my_query->the_post();
  22. $do_not_duplicate[] = $post->ID; ?>
  23. <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
  24. <?php endwhile; ?>
  25. <?php wp_reset_query(); ?>
  26.  
  27. <h1>Loop 3</h1>
  28. <?php $args=array(
  29.       'posts_per_page' => 1,
  30.       'post__not_in' => array_merge($do_not_duplicate, get_option( 'sticky_posts' )),
  31.       'category__in' => array($category->term_id)
  32. );
  33. $my_query = new WP_Query( $args );
  34. while ($my_query->have_posts()) : $my_query->the_post();
  35. $do_not_duplicate[] = $post->ID; ?>
  36. <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
  37. <?php endwhile; ?>
  38. <?php wp_reset_query(); ?>
  39.            
  40. <h1>Loop 4 (leftovers)</h1>
  41. <?php if (have_posts()) : while (have_posts()) : the_post();
  42.  if (in_array($post->ID, $do_not_duplicate)) continue;
  43.  ?>                    
  44. <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
  45. <?php endwhile; ?>
  46. <?php else: ?>
  47. <?php endif; ?>
  48.  
  49. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement