Created
April 11, 2014 14:35
-
-
Save cdils/10473918 to your computer and use it in GitHub Desktop.
Add Previous/Next pagination to single posts within a category. If there are no adjacent posts, don't display anything.
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
<? php //remove this line | |
// Adding pagination before and after post entry in Genesis Framework | |
add_action( 'genesis_before_entry', 'cd_prev_next_posts_nav' ); | |
add_action( 'genesis_after_entry', 'cd_prev_next_posts_nav' ); | |
// Add Prev/Next post navigation within a single category | |
function cd_prev_next_posts_nav() { | |
// Check to see if there are previous and next posts | |
$previous = get_adjacent_post( true, '', true ); | |
$next = get_adjacent_post( true, '', false ); | |
//bail if we're not on a single post with a previous or next post available | |
if ( ! is_single() || ( empty( $next ) || empty( $previous ) ) ) { | |
return; | |
} | |
echo '<div class="archive-pagination">'; | |
// build links to prev/next post in same category | |
$prev_link = previous_post_link( '<div class="pagination-previous alignleft">%link</div>', '« Previous Post', TRUE ); | |
$next_link = next_post_link( '<div class="pagination-next alignright">%link</div>', 'Next Post »', TRUE ); | |
echo '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. Wondering how you would change the code if you wanted to add pagination on a single post but not limit it to within a category?
Could you add simple pagination that would just go to the previous/next post?