Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for Infinite looping next post link within a certain category on a post

$
0
0

based on the docu:

'infinitely looping 'next post' link at the bottom of a post that only links to posts in that category'

if( get_adjacent_post(true, '', false, 'category') ) {   next_post_link($format = '%link', $link = 'Next Article', $in_same_term = true, $taxonomy = 'category'); } else {    $thiscat = get_the_category();    $catslug = $thiscat[0]->slug;    $last = new WP_Query( array( 'posts_per_page' => 1, 'order' => 'ASC', 'category_name' => $catslug      ) );    $last->the_post();    echo '<a href="' . get_permalink() . '">Next Article</a>';    wp_reset_postdata(); }

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>