Files
agroexpert/rfo/related-posts.php

34 lines
969 B
PHP
Raw Normal View History

2025-06-16 20:16:54 +03:00
<?php
$current_post_id = get_the_ID();
// Получаем категории текущего поста
$categories = get_the_category($current_post_id);
if ($categories) {
$category_ids = array_map(function ($category) {
return $category->term_id;
}, $categories);
$args = array(
'category__in' => $category_ids,
'post__not_in' => array($current_post_id),
'posts_per_page' => 3,
);
$related_posts_query = new WP_Query($args);
if ($related_posts_query->have_posts()) {
2025-06-18 13:44:08 +03:00
echo '<div class="related-posts">';
2025-06-16 20:16:54 +03:00
echo '<div class="article-section-title__rfo">Читайте также:</div>';
echo '<div class="articles-preview-rfo">';
while ($related_posts_query->have_posts()) {
$related_posts_query->the_post();
get_template_part('content', 'post-rfo');
}
2025-06-18 13:44:08 +03:00
echo '</div>';
2025-06-16 20:16:54 +03:00
echo '</div>';
wp_reset_postdata();
}
}
?>