Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm on single-work.php for a custom post type called work, inside the loop.

Trying to make two links to the previous and next post.

Using this code:

<?php previous_post_link(); ?>

and

<?php next_post_link(); ?>

But nothing shows up. Am I missing something

Here is my code, very straightforward:

<?php get_header(); ?>
<div class="full" >

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    <?php next_post_link('%link', 'Next post »'); ?>
<?php next_post_link('%link', 'Next post »'); ?>

<?php endwhile; // end of the loop. ?>

</div><!--/full-->  
<?php get_footer(); ?>
share|improve this question

2 Answers 2

What I see in your code is that your next post and previous post codes are appearing within the while loop which shouldn't be within the loop and it should appear like this:

<?php get_header(); ?>
<div class="full" >
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php endwhile; // end of the loop. ?>
<?php next_post_link('%link', 'Next post »'); ?>
<?php next_post_link('%link', 'Next post »'); ?>
</div><!--/full-->  
<?php get_footer(); ?>

Or, you can find it in detail here.

In the above post I found numeric pagination but still it have explained how exactly the pagination works, which is in great detail.

share|improve this answer
    
User 39075, please don't undo grammar corrections done by your fellow users. Here, we value good content and editorial quality. Thanks. Check the help center for more details. –  brasofilo Oct 6 '13 at 13:18

The functions are right; set the params

<?php next_post_link('%link', 'Next post »'); ?>

<?php next_post_link('%link', 'Next post »'); ?>

Well, without seeing any of your code, it's hard to say why. Are there any PHP errors or warnings?

Update

A small example

<?php query_posts( array( 'post_type' => 'page', 'post_status' => 'publish' ) ) ?>
<?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post() ?>
        <!-- do stuff -->

    <div id="nav-single">
        <div class="left"><?php previous_post_link(); ?></div>
        <div class="right"><?php next_post_link(); ?></div>
    </div>

    <?php endwhile; // end of the loop. ?>
    <?php wp_reset_query(); ?>

<?php else : ?>

    <!-- do other stuff here -->

<?php endif ?>
share|improve this answer
    
Those params are optional, putting them in doesn't help any. No PHP errors or anything which is why I'm having trouble figuring it out, its just silent.. –  wesbos Dec 13 '12 at 20:52
    
Yes, but it works on many single templates in many themes. Is ahrd without the source of the template, that we see, where is the problem. It is also possible, that a plugin or functions hook inside the loop and break the template tags. –  bueltge Dec 13 '12 at 20:55
    
I'll update with my code... –  wesbos Dec 13 '12 at 20:57
    
And the CPT is inside the default loop? In your code is a default loop, not several for CPT. But, yes it is possible to hook from a CPT inside the loop and add the CPT. –  bueltge Dec 13 '12 at 21:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.