Custom Post Type Next/Previous Link?

I have a custom post type called portfolio. I need a previous/next link WITHOUT a plugin. Anybody have a solution?

Example post:

<?php get_header(); ?>

<!-- Begin wrap -->
<div class="clear">
<div id="full_container">
<div id="content2">
<div id="content">

<!-- Grab posts -->
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>

<!-- Post title -->
    <?php the_title(); ?>

<!-- The post -->
<?php the_content(); ?>

<!-- Tags -->
<h3 class="tags">
    <?php the_tags('Tags ',"",'<br />'); ?>

<!-- End wrap -->

<!-- Next/Previous Posts -->
<div class="mp_archive2">
<div id="more_posts">
    <div class="oe">
        <?php previous_post_link('%link', '« Previous post', TRUE); ?>

    <div class="re">
        <?php next_post_link('%link', 'Next post »', TRUE); ?>

<?php endwhile; else: ?>
<p>No matching entries found.</p>
<?php endif; ?>
<?php get_footer(); ?>


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.

Leave a Comment