Last active
November 12, 2015 14:15
-
-
Save cjkoepke/e25db5c020aa191566d4 to your computer and use it in GitHub Desktop.
Custom Post Type Pagination Snippet
This file contains hidden or 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 | |
/** | |
* | |
* @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 →</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 ); ?>">← Newer Project</a> | |
<?php endif; | |
} | |
} |
This file contains hidden or 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
/* 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