<?php
		$post_id = get_the_ID();
		$related_query = new WP_Query(array(
			'post_type'      => 'post',
			'category__in'   => wp_get_post_categories( $post_id ),
			'post__not_in'   => array( $post_id ),
			'posts_per_page' => 8
		));
	?>

	<?php if ($related_query->have_posts()) { ?>

	    <div class="related-posts-grid">
	    	<h2>Bài viết liên quan</h2>
	        <?php while ($related_query->have_posts()) { ?>

	            <?php $related_query->the_post(); ?>

	            <div class="grid-item">

	                <a href="<?php the_permalink(); ?>">
	                    <?php the_post_thumbnail('post-thumb-small'); ?>
	                </a>

	                <h5>
	                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
	                </h5>

	            </div>

	        <?php } ?>

	    </div>

	    <?php wp_reset_postdata(); ?>

	<?php } ?>

css

.related-posts-grid h2 {
  font-size: 18px;
  color: #000;
  display: block;
}
.related-posts {
  display: flex;
  flex-wrap: wrap;
  margin-left: -15px;
  margin-right: -15px;
}
.related-posts .grid-item {
  display: flex;
}
.related-posts .grid-item .thumb {
  width: 90px;
  height: 60px;
  margin-right: 10px;
  float: left;
}
.related-posts .grid-item .title {
  flex: 1;
  margin-top: 0;
}
.related-posts .grid-item .title a {
  font-size: 16px;
  color: #545353;
  font-weight: 600;
}

 

Bài viết liên quan

post-no-image

Add the Meta Box Upload Multiple Images and multiple metabox

post-no-image

Add the Meta Box Repeat

post-no-image

Kỹ thuật debounce trong javascript – Trì hoãn nhập từ khóa trong ô input

post-no-image

Thêm VS Code snippets

post-no-image

Query only seach by title

post-no-image

Hướng dẫn tạo form có validate, upload file nhiều bước và xử lý ajax