Skip to content

Instantly share code, notes, and snippets.

@cphilippsen
Created January 21, 2015 15:02
Show Gist options
  • Save cphilippsen/0c125ea1e2bf83aea23f to your computer and use it in GitHub Desktop.
Save cphilippsen/0c125ea1e2bf83aea23f 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>
@cphilippsen
Copy link
Author

To paginate all items in a Custom Post Type, one should use get_previous_post() and get_next_post(). The 'taxonomy' value is based on paginating in the same Custom Taxonomy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment