Skip to content

Instantly share code, notes, and snippets.

@cjkoepke
Last active November 12, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cjkoepke/e25db5c020aa191566d4 to your computer and use it in GitHub Desktop.
Save cjkoepke/e25db5c020aa191566d4 to your computer and use it in GitHub Desktop.
Custom Post Type Pagination Snippet
<?php
/**
*
* @author Calvin Koepke
* @link http://www.calvinkoepke.com/add-pagination-to-custom-post-types-in-genesis/
*
* Add previous and next buttons to custom post types.
*/
add_action('genesis_before_content', 'ck_custom_navigation_links', 5 )
function ck_custom_navigation_links() {
// Check to see if the post is a custom post type, and if it is on the post view.
// If so, execute the function.
// Replace 'work' with your custom post type slug.
if( is_singular ( 'work' ) ) {
// Set variables for ease of use.
$older_post = get_previous_post();
$newer_post = get_next_post();
// If the $older_post returns a value, display the markup.
if ( ! empty($older_post) ): ?>
<a class="pagination-older" href="<?php echo get_permalink( $older_post->ID ); ?>">Previous Project &rarr;</a>
<?php endif;
// If the $newer_post returns a value, display the markup.
if ( ! empty($newer_post) ): ?>
<a class="pagination-newer" href="<?php echo get_permalink( $newer_post->ID ); ?>">&larr; Newer Project</a>
<?php endif;
}
}
/* Custom Post Type Pagination
--------------------------------------------- */
.pagination-older {
float: right;
margin-bottom: 10px;
}
.pagination-newer {
float: left;
margin-bottom: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment