1

I'm trying to add links "Previous Post" and "Next Post" in my single.php file without success because previous_posts_link and next_posts_link dont return anything.

Honestly I do not know where in the loop put these buttons.

Thanks.

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

<div class="post-content">
<?php the_title(); the_content(); ?>
</div>

<?php endwhile; ?>

<ul class="nav-posts">
    <li class="prev-link"><?php next_posts_link('« Previous Post') ?></li>
    <li class="next-link"><?php previous_posts_link('Next Post»') ?></li>
</ul>

<?php endif; ?> 

4

next_posts_link and previous_posts_link (plural) are for archive pagination. For single posts you want next_post_link and previous_post_link (singular).

  • Ok thanks; now i can see the labels: "Previous Page" and "Next Page", but they dont have a link, is just text. – Sema Hernández Oct 30 '14 at 20:22
0

I was looking for this:

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

<div class="post-content">
<?php the_title(); the_content(); ?>
</div>

<?php endwhile; ?>

<ul class="nav-posts">
    <li class="prev-link"><?php previous_post_link( '%link', '« Previous Post' ); ?></li>
    <li class="next-link"><?php next_post_link( '%link', 'Next Post »' ); ?></li>
</ul>

<?php endif; ?> 

Thanks Milo for the aclaration (plural, singular)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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