Infinite next / prev post in single.php page

Question

I have a question regarding this code. When the last entry appears in then “next” I show the same page all the time.
In addition, I would like to add a thumbnail display of the next post and a title to this. Is it possible?

<?php
    if( get_adjacent_post(false, '', true) ) {
            previous_post_link('%link' , '%title', '&larr; ');
        } else {
            $first = new WP_Query('cat=3&posts_per_page=1&order=DESC'); $first->the_post();
             echo '<a href="' . get_permalink() . '">&larr;</a>';
             echo ('%title');
            wp_reset_query();
        };

        if( get_adjacent_post(false, '', false) ) {

        } else {
            $last = new WP_Query('cat=3&posts_per_page=1&order=ASC'); $last->the_post();
                echo '<a href="' . get_permalink() . '">Next Post &rarr;</a>';
            wp_reset_query();
        };

    ?>

Please help, gentlemen and ladies

0
GGQa 1 month 2021-08-25T12:57:57-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse