Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="single-post__related">
- <?php
- $categories = get_the_terms(get_the_id(), 'category');
- $cat_ids = array();
- foreach( $categories as $category ){
- $cat_ids[] = $category->term_id;
- }
- $related = new WP_Query([
- 'post_type' => 'post',
- 'posts_per_page' => 3,
- 'category__in' => $cat_ids,
- 'post__not_in' => array( $post->ID )
- ]);
- while($related->have_posts()) : $related->the_post();
- ?>
- <div class="single-post__related-item">
- <a href="<?php the_permalink(); ?>">
- <?php the_post_thumbnail(); ?>
- <h6><?php the_title(); ?></h6>
- </a>
- <span><?php the_time('F d, Y'); ?></span>
- </div>
- <?php endwhile; wp_reset_postdata(); ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement