Открываем шаблон отдельной записи (в теме Twenty Sixteen это файл template-parts/content-single.php) и в самом низу добавляем:
Похожие записи из тех же разделов
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php $cats = wp_get_post_terms( get_the_ID(), 'category' ); if ($cats) { $cats_ids = array(); foreach( $cats as $related_cat ) { $cats_ids[] = $related_cat->term_id; } $args=array( 'category__in' => $cats_ids, 'post__not_in' => array($post->ID), 'showposts'=>3, // Количество записей 'caller_get_posts'=>1, 'orderby' => 'rand' // Выводим в случайном порядке ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo '<h4>На эту тему:</h4>'; while ($my_query->have_posts()) { $my_query->the_post(); ?> <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> <?php the_post_thumbnail( 'medium', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?> </a> <?php the_title( sprintf('<a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a>'); ?> <time> <?php the_date(); ?> </time> <?php } wp_reset_query(); } } ?> |
Похожие записи из тех же тегов
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php $tags = wp_get_post_tags($post->ID); if ($tags) { $tag_ids = array(); foreach($tags as $related_tag) $tag_ids[] = $related_tag->term_id; $args=array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'showposts'=>3, // Количество записей 'caller_get_posts'=>1, 'orderby' => 'rand' // Выводим в случайном порядке ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo '<h4>На эту тему:</h4>'; while ($my_query->have_posts()) { $my_query->the_post(); ?> <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> <?php the_post_thumbnail( 'medium', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?> </a> <?php the_title( sprintf('<a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a>'); ?> <time> <?php the_date(); ?> </time> <?php } wp_reset_query(); } } ?> |
1. Похожие записи из той же категории и той же таксаномии. Например категория - строительство, таксономия - город Москва?
2. Похожие записи этого автора ?