Advertisement
Guest User

Untitled

a guest
May 4th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. // put all the category IDs of current post into an array
  2. $categories = get_the_category( $post->ID );
  3. $category_id_array = array();
  4. foreach ( $categories as $category ) {
  5.     $category_id_array[] = $category->cat_ID;
  6. }
  7.  
  8. // define how many thumbnails to show (at most)
  9. $thumbnail_max = 10;
  10.  
  11. // grab all posts in the same categories as the current post
  12. $category_thumb_args = array( 'category__in' => $category_id_array, 'posts_per_page => $thumbnail_max', 'exclude' => $post->ID );
  13. $category_thumb_query = new WP_Query( $category_thumb_args );
  14.  
  15. // if there are posts loop through them
  16. if ( $category_thumb_query->have_posts() ) :
  17.     while($category_thumb_query->have_posts()) : $category_thumb_query->the_post();
  18.         // if the post has a post thumbnail display it
  19.         if ( has_post_thumbnail() ) :
  20.             the_post_thumbnail( 'thumbnail' );
  21.         endif;
  22.     endwhile;
  23. endif;
  24.  
  25. // reset the query since we used the_post()
  26. wp_reset_query();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement