Advertisement
alchymyth

do not dup in category foreach loop

Apr 11th, 2011
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2. //for each category, show 3 posts
  3. $cat_args=array(
  4.   'orderby' => 'name',
  5.   'order' => 'ASC'
  6.    );
  7.  
  8. $do_not_duplicate = array();
  9.  
  10. $categories=get_categories($cat_args);
  11.   foreach($categories as $category) {
  12.     $args=array(
  13.       'showposts' => 3,
  14.      'post__not_in' => $do_not_duplicate,
  15.       'category__in' => array($category->term_id),
  16.       'caller_get_posts'=>1
  17.     );
  18.     $posts=get_posts($args);
  19.       if ($posts) {
  20.         echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
  21.         foreach($posts as $post) {
  22.           setup_postdata($post);
  23.     $do_not_duplicate[] = $post->ID; ?>
  24.           <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  25.           <?php
  26.         } // foreach($posts
  27.       } // if ($posts
  28.     } // foreach($categories
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement