Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // put all the category IDs of current post into an array
- $categories = get_the_category( $post->ID );
- $category_id_array = array();
- foreach ( $categories as $category ) {
- $category_id_array[] = $category->cat_ID;
- }
- // define how many thumbnails to show (at most)
- $thumbnail_max = 10;
- // grab all posts in the same categories as the current post
- $category_thumb_args = array( 'category__in' => $category_id_array, 'posts_per_page => $thumbnail_max', 'exclude' => $post->ID );
- $category_thumb_query = new WP_Query( $category_thumb_args );
- // if there are posts loop through them
- if ( $category_thumb_query->have_posts() ) :
- while($category_thumb_query->have_posts()) : $category_thumb_query->the_post();
- // if the post has a post thumbnail display it
- if ( has_post_thumbnail() ) :
- the_post_thumbnail( 'thumbnail' );
- endif;
- endwhile;
- endif;
- // reset the query since we used the_post()
- wp_reset_query();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement