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!