Advertisement
Guest User

Associated category preview

a guest
Aug 10th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <div class="thumbnails container_24">
  2. <!-- loop in thumbnails for the relevant category -->
  3. <?php
  4. // put all the category IDs of current post into an array
  5. $categories = get_the_category( $post->ID );
  6. $category_id_array = array();
  7. foreach ( $categories as $category ) {
  8. $category_id_array[] = $category->cat_ID;
  9. }
  10.  
  11. // define how many thumbnails to show (at most)
  12. $thumbnail_max = 6;
  13.  
  14. // grab all posts in the same categories as the current post
  15. $category_thumb_args = array( 'category__in' => $category_id_array, 'posts_per_page => $thumbnail_max', 'exclude' => $post->ID );
  16. $category_thumb_query = new WP_Query( $category_thumb_args );
  17.  
  18. // if there are posts loop through them
  19. if ( $category_thumb_query->have_posts() ) :
  20. while($category_thumb_query->have_posts()) : $category_thumb_query->the_post(); ?>
  21. <?php if ( has_post_thumbnail() ) :?>
  22. <div class="grid_8 newsbox">
  23. <div class="news-thumbnail"><?php the_post_thumbnail(); ?></div>
  24. <div class="news-description">
  25. <a class="news-link" href="<?php the_permalink() ?>" rel="<?php the_ID(); ?>" title="Nyhet - <?php the_title_attribute(); ?>">
  26. <?php the_title('<p class="news-titel">', '</p>'); ?>
  27. <div class="news-excerpt"><?php the_excerpt(); ?></div>
  28. <p class="news-date"><?php the_time('F j, Y'); ?></p>
  29. </a>
  30. </div> <!-- end newsdescripton -->
  31. <div class="news-tag"></div>
  32. </div> <!-- end newsbox -->
  33. <?php endif;
  34. endwhile;
  35. endif;
  36. // reset the query since we used the_post()
  37. wp_reset_query();
  38. ?>
  39. <!-- stop looping in thumbnails -->
  40. </div> <!-- end thumbnails -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement