Advertisement
alchymyth

3 loops, no duplicates

Jun 21st, 2011
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. FIRST LOOP
  2.  
  3. <?php $do_not_duplicate = array();
  4. $my_query = new WP_Query(array('posts_per_page' => 3, 'post__in' => get_option( 'sticky_posts' ), 'caller_get_posts' => 1 ) );
  5. while ($my_query->have_posts()) : $my_query->the_post();
  6. $do_not_duplicate[] = $post->ID; ?>
  7.  
  8. <?php
  9. $category = get_the_category();
  10. if ($category) {
  11. echo '<a href="' . get_category_link( $category[0]->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a>';
  12. }
  13. ?>
  14.  
  15. <br>
  16.  
  17. <a href="<?php the_permalink() ?>" rel="bookmark" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a>
  18.  
  19. <br>
  20.  
  21. <?php endwhile;?>
  22. <?php wp_reset_query(); ?>
  23.  
  24. SECOND LOOP
  25.  
  26. <?php
  27. $my_query = new WP_Query(array('posts_per_page' => 4, 'post__not_in' => array_merge($do_not_duplicate, get_option( 'sticky_posts' )) ) );
  28. while ($my_query->have_posts()) : $my_query->the_post();
  29. $do_not_duplicate[] = $post->ID; ?>
  30.  
  31. <a href="<?php the_permalink() ?>" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br>
  32. <br>
  33.  
  34. <?php endwhile;?>
  35. <?php wp_reset_query(); ?>
  36.  
  37. THIRD LOOP
  38.  
  39. <?php
  40. //for each category, show 1 post
  41. $cat_args=array(
  42. 'orderby' => 'name',
  43. 'order' => 'ASC'
  44. );
  45.  
  46. $categories=get_categories($cat_args);
  47. foreach($categories as $category) {
  48. $args=array(
  49. 'numberposts' => 1,
  50. 'post__not_in' => array_merge($do_not_duplicate,get_option( 'sticky_posts' )),
  51. 'category__in' => array($category->term_id)
  52. );
  53.  
  54. $posts=get_posts($args);
  55. if ($posts) {
  56. $ncat = '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
  57. foreach($posts as $post) {
  58. setup_postdata($post);
  59. $do_not_duplicate[] = $post->ID; ?>
  60.  
  61. <a href="<?php the_permalink() ?>" title="Read: <?php the_title(); ?>"><?php the_title(); ?></a><br>
  62. <br>
  63. <?php the_excerpt(); ?><br>
  64. <br>
  65. By <?php the_author_link(); ?>, <?php the_time('F j, Y'); ?> | In: <?php echo $ncat ?><?php comments_popup_link('<b>No Comments</b>', '<b>1 Comment</b>', '<b>% Comments</b>', '', '<b>Comments off</b>'); ?><br>
  66. <br>
  67.  
  68. <?php
  69. } // foreach($posts
  70. } // if ($posts
  71. } // foreach($categories
  72. ?>
  73.  
  74. <?php wp_reset_query(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement