File: /home/dkhp464/public_html/wp-content/themes/DaKhoaHongPhat/template-parts/content-single.php
<h1 class=""><?= get_the_title() ?></h1>
<div class="post-content">
<?= the_content() ?>
</div>
<hr class="bg-secondary border-2 border-top border-secondary my-5">
<?php
$post_id = get_the_ID();
$cat_ids = [];
$categories = get_the_category($post_id);
if (!empty($categories) && !is_wp_error($categories)) :
foreach ($categories as $category) :
array_push($cat_ids, $category->term_id);
endforeach;
endif;
$current_post_type = get_post_type($post_id);
$query_args = [
'orderby' => 'rand',
'post_type' => $current_post_type,
'post__not_in' => [$post_id],
'posts_per_page' => '3',
];
$related_cats_post = new WP_Query($query_args);
if ($related_cats_post->have_posts()) :
?>
<div class="relate-posts d-none">
<h4 class="title-relate-post">BÀI VIẾT LIÊN QUAN</h4>
<div class="row gy-4">
<?php
while ($related_cats_post->have_posts()) : $related_cats_post->the_post(); ?>
<div class="col-lg-4 col-md-6">
<article class="">
<div class="row">
<div class="col-md-12 col-5">
<a href="<?= the_permalink() ?>"
title="<?= the_title() ?>">
<?= the_post_thumbnail('crop_medium', [
'class' => 'h-auto img-fluid d-block m-auto w-100',
'alt' => get_the_title(),
]); ?>
</a>
</div>
<div class="col-md-12 col-7">
<h5 class="mt-md-3 mt-0">
<a class="content-relate"
href="<?= the_permalink() ?>"
title="<?= the_title() ?>"
onclick="setPostViews(<?php echo get_the_ID(); ?>)">
<?php the_title(); ?>
</a>
</h5>
</div>
</div>
</article>
</div>
<?php endwhile; ?>
</div>
</div>
<?php
wp_reset_postdata();
endif;
?>
<div class="sidebar-after d-xl-none d-block"></div>