1

I've been developing a Wordpress site lately and have come across an issue. I need the user to be able to navigate between posts, I'm using the standard Wordpress functions previous_post_link() and next_post_link() which should in THEORY output the links to the next and previous posts in the database... BUT the only links that appear are in the case of the latest post; the first post that was published and in the case of the first post that was published; the latest post.

There are 5 posts and they all produce the same links, I'm not doing anything silly or outside of the box.

I also had some initial issues with pagination on the main blog feed but that appears to be fixed now....

Here is my code:

single.php

<?php get_header(); the_post();?>

    <div class="page-heading--cloud">
        <h1>BLOG</h1>
    </div>

    <article class="single">
        <div class="single__wrap">
            <img class="single__image" src="<?php echo Image::get(wp_get_attachment_url(get_post_thumbnail_id($post->ID))); ?>">
            <p class="single__date">Posted on <?php the_time('jS F Y'); ?> by <?php the_author(); ?></p>
            <h1 class="single__title"><?php the_title(); ?></h1>
            <div class="single__content">
                <?php the_content(); ?>
            </div>
        </div>
    </article>

    <div class="page-navigation">
        <hr class="page-navigation__line">
        <p class="page-navigation__link"><?php previous_post_link('<i class="fa fa-long-arrow-left"></i> %link'); ?></p>
        <p class="page-navigation__link"><?php next_post_link('%link <i class="fa fa-long-arrow-right"></i>'); ?></p>
        <hr class="page-navigation__line">
    </div>

<?php get_footer();?>

and here is the main blog feed:

index.php

<?php get_header(); ?>

    <!-- Side info -->
    <div class="page-heading--cloud">
        <h1>BLOG</h1>
    </div>

    <div class="blog page-data">
        <article class="page-data__main">
            <?php while(have_posts()) : the_post(); ?>
                <div class="blog__post">
                    <img class="blog__image" src="<?php echo Image::get(wp_get_attachment_url(get_post_thumbnail_id($post->ID))); ?>">
                    <div class="blog__post__wrap">
                        <p class="blog__post__date">Posted on <?php the_time('jS F Y'); ?> by <?php the_author(); ?></p>
                        <h2 class="blog__post__title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                        <p class="blog__post__excerpt"><?php echo get_the_content_excerpt(30); ?></p>
                        <a class="blog__post__more" href="<?php the_permalink(); ?>">Continue Reading <i class="fa fa-arrow-right"></i></a>
                    </div>
                </div>
            <?php endwhile;?>

            <?php if(!have_posts()) : ?>
                <h2>There are no posts to display at this time.</h2>
            <?php endif; ?>

        </article>

        <?php get_template_part('partials/sidebar', 'landing'); ?>
    </div>

    <div class="page-navigation">
        <hr class="page-navigation__line">
        <p class="page-navigation__link"><?php previous_posts_link('<i class="fa fa-long-arrow-left"></i> Newer Posts'); ?></p>
        <p class="page-navigation__link"><?php next_posts_link('Older Posts <i class="fa fa-long-arrow-right"></i>'); ?></p>
        <hr class="page-navigation__line">
    </div>
<?php get_footer(); ?>

I hope that someone is able help me with this issue, if you're able to direct me to potential fixes that would be great! Though I have already searched and searched, tried peoples suggestions etc which is why I've chosen to make this post.

If something isn't clear please let me know :)

Thanks in advance!

4
  • 1
    Try this as its tested and works wordpress.stackexchange.com/questions/157208/… – Brad Dalton Aug 21 '14 at 13:45
  • I don't quite understand what you mean by linking this? Mine just doesn't render anything for the links that aren't working, I'm not styling anything unusually so that can't be an issue! – CraigChilds94 Aug 21 '14 at 14:30
  • In the post that Brad linked to, have to checked my answer. It really seems that you have exactly the same problem – Pieter Goosen Aug 21 '14 at 17:31
  • I've tried using the "fix" and it doesn't appear to make a difference other than visually! – CraigChilds94 Aug 22 '14 at 8:19
1

I've realised what the issue was... some of my posts were generated (for development purposes) using bulk creator which appears to not create a complete post! When I create a post manually using the WP backend my code works fine, thanks for the suggestions anyway guys!

2
  • I think you have nailed it and found a solution to the linked question as well. This is rather unusual. Thanks for posting your answer – Pieter Goosen Aug 22 '14 at 9:17
  • Yes this is unusual and I still don't understand why it happens, maybe I had a conflicting problem between my version of that plugin and the version of Wordpress! – CraigChilds94 Sep 12 '14 at 8:29

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.