Created
January 21, 2015 15:02
-
-
Save cphilippsen/0c125ea1e2bf83aea23f to your computer and use it in GitHub Desktop.
WordPress Pagination on single.php from the same category and/or taxonomy
This file contains 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
<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
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.