Genesis and WordPress Tutorials
by Sridhar Katakam 6 Comments Favorited: 4 times
Updated on March 30, 2017.
Genesis has a genesis_prev_next_post_nav()
function which can be hooked to one of the many places like genesis_after_loop
on single entry pages to display links to previous and next posts. It is set to work (when enabled via code) only for regular blog posts.
If you would like to do the same but for entries of a Custom Post Type, just add the following in your child theme's functions.php:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Find my tutorials helpful and wish to donate?
Session expired
Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page.
My portfolio in Portfolio Pro is has three portfolio types within the portfolio. One can view the entire portfolio, or one of the three portfolio types. Are there variations to this code snippet that allows one to go to the previous or next portfolio item within a portfolio type? Right now the previous/next links go through the entire portfolio.
Thanks
Yes.
Hope you have paid attention to
?
Sorry Sridhar but no luck.
Below is the php for my portfolio on http://rroden.com/portfolio/ When I leave “previous_post_link();” & “next_post_link();” as they are, next/previous buttons work.
But when I edited links to by adding into the parentheses ( ‘« %link’, ‘%title’, true, ”, ‘book_type’ );” with any combination of possible options to replace ‘book_type” it only breaks the button.
// Add post navigation for “portfolio” CPT
add_action( ‘genesis_after_loop’, ‘sk_prev_next_post_nav’ );
function sk_prev_next_post_nav() {
if ( ! is_singular( ‘portfolio’ ) ) // Replace ‘portfolio’ with the name of your CPT
return;
genesis_markup( array(
'html5' => '',
'xhtml' => '',
'context' => 'adjacent-entry-pagination',
) );
echo '';
previous_post_link();
echo '';
echo '';
next_post_link();
echo '';
echo '</div>';
}
Any ideas? – Thanks
Hi Sridhar,
I experience the same as the previous poster…
When using: previous_post_link(); the link appears, but does not stay in the category. I use the code as:
if ( ! is_singular( ‘post’ ) )
When I use: previous_post_link ( ‘« %link’, ‘%title’, true, ‘ ‘, ‘nieuws’ );
‘nieuws’ is the category I want the navigation to stay in – When using that code, the previous link just does not appear.
I checked a lot of other sites and the codex, but just can not get it to work
Are you talking about posts or CPT entries?
Is
nieuws
the built-in WordPress category or a custom taxonomy?In the end changed the last bit to:
previous_post_link( ‘« %link’, ‘%title’, true );
– and now it works 🙂