Skip to content

Instantly share code, notes, and snippets.

@morgyface
Created February 10, 2017 15:41
Show Gist options
  • Select an option

  • Save morgyface/aed4bc041536e229f356a341e3103d09 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/aed4bc041536e229f356a341e3103d09 to your computer and use it in GitHub Desktop.
WordPress | Next / Previous Post Links | Traversing posts
<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 . '">&larr;' . $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 . '&rarr;</a>';
}
echo '</div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment