Forked from banago/infinite-previous-next-looping.php
Created
September 7, 2020 06:39
-
-
Save hieuhuynh93/0dfa0b9fff0c32f94a7e5731b974420e to your computer and use it in GitHub Desktop.
Infinite next and previous post looping in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Infinite next and previous post looping in WordPress | |
| */ | |
| if( get_adjacent_post(false, '', true) ) { | |
| previous_post_link('%link', '← Previous Post'); | |
| } else { | |
| $first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post(); | |
| echo '<a href="' . get_permalink() . '">← Previous Post</a>'; | |
| wp_reset_query(); | |
| }; | |
| if( get_adjacent_post(false, '', false) ) { | |
| next_post_link('%link', 'Next Post →'); | |
| } else { | |
| $last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post(); | |
| echo '<a href="' . get_permalink() . '">Next Post →</a>'; | |
| wp_reset_query(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment