54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
// Читайте также
|
|
|
|
if (! defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
$post_id = (int) get_the_ID();
|
|
|
|
$cat_ids = wp_get_post_categories($post_id);
|
|
|
|
$args = array(
|
|
'posts_per_page' => 3,
|
|
'post_type' => 'post',
|
|
'post_status' => 'publish',
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
'post__not_in' => array( $post_id ),
|
|
);
|
|
if (! empty($cat_ids)) {
|
|
$args['category__in'] = $cat_ids;
|
|
}
|
|
|
|
$query = new WP_Query($args);
|
|
|
|
if (! $query->have_posts()) {
|
|
return;
|
|
}
|
|
?>
|
|
<div class="read-block">
|
|
<h2 class="read-block_title">Читайте также</h2>
|
|
<div class="read-blocks-wrapper">
|
|
<?php
|
|
while ($query->have_posts()) :
|
|
$query->the_post();
|
|
?>
|
|
<article class="block-new">
|
|
<a href="<?php the_permalink(); ?>">
|
|
<div class="block-new_img">
|
|
<?php if (has_post_thumbnail()) : ?>
|
|
<?php the_post_thumbnail(); ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<h3 class="block-new_title"><?php the_title(); ?></h3>
|
|
</a>
|
|
</article>
|
|
<?php
|
|
endwhile;
|
|
wp_reset_postdata();
|
|
?>
|
|
</div>
|
|
</div>
|