Wordpress - Custom Post Type Next/Previous Link?
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" ">« Previous post<br /><strong>"'. $prev_title . '"</strong></a>' . "\n";
}
$next_post = get_next_post();
if($next_post) {
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" class=" ">Next post »<br /><strong>"'. $next_title . '"</strong></a>' . "\n";
}
?>
If you need next/previous links for single posts, there is the built in next_post_link
function and matching previous_post_link
, both of which should probably be used within the loop.
For archives, use next_posts_link
and previous_posts_link
.
All of these will work fine with custom post types.