The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Next / Previous Posts Not Working Reply To: WordPress Next / Previous Posts Not Working


Found a fix for this just in case anyone ever reads this and requires then same answer. My older posts link wasn’t working as I hadn’t set the paged variable.

My code looks like this now.


<img src="<?php print IMAGES; ?>/header-blog.jpg" alt="Blog Header Image" width="999" height="250">

<section role="main">

        <?php $page = get_page_by_title('the blog'); $content = apply_filters('the_content', $page->post_content); echo $content; ?>

        <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $blog_posts = new WP_Query('showposts=4' . '&paged='.$paged);

            if ( $blog_posts->have_posts() ) : while ( $blog_posts->have_posts() ) : $blog_posts->the_post(); ?>

            <?php the_title(); ?>

        <?php endwhile; ?>

        <nav id="post-nav">
            <span class="prev"><?php next_posts_link( '&larr; View Older Posts', $blog_posts->max_num_pages ); ?></span>
            <?php previous_posts_link('<span class="next">' .( 'View more Recent Posts &rarr;' ). '</span>'); ?>

        <?php else:  ?>
            <p>Sorry it looks like you need to add some posts to this blog!</p>
        <?php endif; wp_reset_query(); ?>