Skip to content

Instantly share code, notes, and snippets.

@kagaim
Forked from cphilippsen/pagination.php
Created August 22, 2017 19:36
Show Gist options
  • Save kagaim/6945169c0eeb011ca44f5e76c7409483 to your computer and use it in GitHub Desktop.
Save kagaim/6945169c0eeb011ca44f5e76c7409483 to your computer and use it in GitHub Desktop.
WordPress Pagination on single.php from the same category and/or taxonomy
<div id="pagination">
<?php
$prev_post = get_previous_post(true, '', 'taxonomy');
$next_post = get_next_post(true, '', 'taxonomy');
?>
<?php if (!empty( $prev_post )): ?>
<div class="prev">
<a href="<?php echo get_permalink( $prev_post->ID ); ?>">
<div class="title"><?php echo get_the_title($prev_post); ?></div>
</a>
</div>
<?php endif; ?>
<?php if (!empty( $next_post )): ?>
<div class="next">
<a href="<?php echo get_permalink( $next_post->ID ); ?>">
<div class="title"><?php echo get_the_title($next_post); ?></div>
</a>
</div>
<?php endif; ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment