So I've been working on my portfolio site for awhile now and just pushed the first "ok to be live version" last night. I gave it a quick QA and found some bugs that I am aware of, but the one that is really stumping me is why the "next Post" and "Previous Post" links are not showing up on my single posts. The index.php paginates fine. I've left my js and css files uncompressed if anyone needs to take a look at them.

First, here's a link to a screenshot of the inspector. You'll notice that the markup has been php'd in from the nav.php file, but the spans where the anchor tags should be are empty:


And here is my code for my single.php:

<?php get_header(); ?>

<main role="main" class="blog-post">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <article title="<?php the_title(); ?>">

            <section class="banner">
                        <h1><?php the_title(); ?></h1>
                        <h3><?php the_date(); ?></h3>
                    $bannerImg = get_field('blog_post_banner_image');
                    if( !empty($bannerImg) ): ?>
                    <img src="<?php echo $bannerImg['url']; ?>" alt="<?php echo $bannerImg['alt']; ?>" />
                <?php endif; ?>

            <section class="the-post">
                        <?php the_content(); ?>

    <?php endwhile; endif; ?>


<?php include (TEMPLATEPATH . '/_/inc/nav.php' ); ?>

And The code from the nav.php file:

<nav role="navigation" class="blog-pagination">
    <span class="prev-post"><?php echo get_next_posts_link('Older Posts', '1000') ?></span>
    <span class="next-post"><?php echo get_previous_posts_link('Newer Posts', '1000') ?></span>

So basically since my internal wordpress blog is non functioning (pagination between posts anyways) I've swapped the menu link for my Medium account where I've copied all my posts to.

Here's the link to my website: http://and-rew.com

And to get to the wordpress blog piece you'll need to go here: http://and-rew.com/writing

I've got it set to 4 posts per index page right now so I can get the next and previous buttons on the index.php archive.

I've built many sites in wordpress and have never had this issue before. The only thing that might be affecting things is that I have a pagination system (all php not plugin) for the child pages of the parent page 'Work'. Other than that being the wrench in the cog, I have no ideas.

1 Answer 1


get_next_posts_link() won't work in is_single() context - see source - and is intended for paged content.

For the is_single() context use next_post_link() and previous_post_link() to echo the output. Or to return the output get_next_post_link() and get_previous_post_link().

  • That worked! Thank you! Is there a way to just have each query output the url to the next post so I can add an SVG in there for larger screens then hide those on small screens and display: none; the SVGs and display some text wrapped in a span? Also, I only made the change on my dev server so you won't see it live yet. Commented Jan 15, 2015 at 15:39
  • That may have been what that link to the link-template.php is, but my PHP knowledge isn't super great. Commented Jan 15, 2015 at 15:41
  • Take a look at the format and link parameter, they offer some possibilities for changing the markup. That should normally be enough. How use that or if it isn't enough for your purpose another solution would another/new question though. Before you ask do a site search for existing resources. If you are still having problems, then ask a new question. This one is resolved as far as I am concerned. Hope that helps. @andandandandrew Commented Jan 15, 2015 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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