Created
February 10, 2017 15:41
-
-
Save morgyface/aed4bc041536e229f356a341e3103d09 to your computer and use it in GitHub Desktop.
WordPress | Next / Previous Post Links | Traversing posts
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
| <style> | |
| div.traverse {width: 100%; clear: both} | |
| div.traverse a {display: block; width: 50%} | |
| div.traverse a.prev {float: left} | |
| div.traverse a.next {float: right; text-align: right} | |
| </style> | |
| <?php | |
| // The traverse navigation to adjacent posts | |
| $prev_post = get_adjacent_post(false, '', true); | |
| $next_post = get_adjacent_post(false, '', false); | |
| if ( $prev_post || $next_post ) { | |
| echo '<div class="traverse">'; | |
| if ( $prev_post ) { | |
| $prev_link = get_permalink( $prev_post ); | |
| $prev_title = get_the_title( $prev_post ); | |
| echo '<a class="prev" href="' . $prev_link . '">←' . $prev_title . '</a>'; | |
| } | |
| if ( $next_post ) { | |
| $next_link = get_permalink( $next_post ); | |
| $next_title = get_the_title( $next_post ); | |
| echo '<a class="next" href="' . $next_link . '">' . $next_title . '→</a>'; | |
| } | |
| echo '</div>'; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment