Single post navigation links are valuable because they link all your posts together. This increases page views and acts a bit like a sitemap which the search engines can follow.
Its pretty easy to add next and previous nav links at the end of all your single posts. But what about adding them to all posts using one specific post type?
As an example, you may have a portfolio where you want all single posts assigned to that specific portfolio post type linked together. And you may not want to link other post types to the posts assigned to this custom post type.
Simply copy the code below from the view raw link & paste it in your child themes functions.php file using a text editor.
Here’s 2 different code snippets which enable you to link all posts assigned to any custom post type.
add_action( 'genesis_entry_footer', 'wpsites_single_cpt_navigation' );
function wpsites_single_cpt_navigation() {
if ( is_singular( 'portfolio' ) ) {
echo'<div class="alignleft">';
previous_post_link();
echo'</div>';
echo'<div class="alignright">';
next_post_link();
echo'</div>';
} }
You can also code it like this which checks if your child theme is using XHTML or HTML 5 markup and hooks:
add_action( 'genesis_entry_footer', 'wpsites_single_cpt_navigation' );
function wpsites_single_cpt_navigation() {
if ( ! is_singular( 'portfolio' ) )
return;
genesis_markup( array(
'html5' => '<div %s>',
'xhtml' => '<div class="navigation">',
'context' => 'adjacent-entry-pagination',
) );
echo '<div class="pagination-previous alignleft">';
previous_post_link();
echo '</div>';
echo '<div class="pagination-next alignright">';
next_post_link();
echo '</div>';
echo '</div>';
}
Leave a Reply
You must be logged in to post a comment.