Advertisement
Guest User

Untitled

a guest
May 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <div class="single-post__related">
  2. <?php
  3. $categories = get_the_terms(get_the_id(), 'category');
  4.  
  5. $cat_ids = array();
  6. foreach( $categories as $category ){
  7. $cat_ids[] = $category->term_id;
  8. }
  9.  
  10. $related = new WP_Query([
  11. 'post_type' => 'post',
  12. 'posts_per_page' => 3,
  13. 'category__in' => $cat_ids,
  14. 'post__not_in' => array( $post->ID )
  15. ]);
  16.  
  17. while($related->have_posts()) : $related->the_post();
  18. ?>
  19.  
  20. <div class="single-post__related-item">
  21. <a href="<?php the_permalink(); ?>">
  22. <?php the_post_thumbnail(); ?>
  23. <h6><?php the_title(); ?></h6>
  24. </a>
  25. <span><?php the_time('F d, Y'); ?></span>
  26. </div>
  27. <?php endwhile; wp_reset_postdata(); ?>
  28. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement