Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Выводит ссылку (HTML тег A) на смежные записи (следующая/предыдущая).
- *
- * @param string $course принимает значение next/prev.
- */
- function da_the_adjacent_post_link( $course = '' ){
- global $post;
- $course = ( $course == 'prev' ) ? true : false;
- $order = ( $course ) ? 'DESC' : 'ASC';
- $link = get_adjacent_post_link( '%link', '%title', true, '', $course );
- if ( ! $link ){
- $term = get_the_terms( $post->ID, 'category' );
- $term = $term[0];
- $article = get_posts([
- 'numberposts' => 1,
- 'exclude' => $post->ID,
- 'category' => $term->term_id,
- 'order' => $order
- ]);
- if ( empty($article) )
- return false;
- else
- $article = $article[0];
- $link = sprintf( '<a href="%s" rel="prev">%s</a>', get_the_permalink($article->ID), $article->post_title );
- }
- echo $link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement