WordPress Blog Pagination Not Working

18,203

Solution 1

Check your WP loop in the category.php file (aka archive.php). It must contain the following:

if (have_posts()) : while (have_posts()) : the_post();

and finished with:

endwhile; endif;

Solution 2

I have played with the "posts pages" too but I'm getting no result.

Only working solution for me was a custome query in combination with the Page-Navi Plugin.

In my template i have the following code:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'post_type'         => 'post',
        'orderby'           => 'date',
        'order'             => 'DESC',
        'post_status'       => 'publish',
        'posts_per_page'    => 5,
        'paged'             => $paged,
    );
    $q = new WP_Query( $args );

    if ( $q->have_posts() ) {
        $displaylist = '<div class="list-group">';

        while ( $q->have_posts() ) {
            $q->the_post();

            // build up your entry

            unset( $displayTag );
        }

        $displaylist .= '</div>';

        echo( $displaylist );

        wp_pagenavi( array( 'query' => $q ) );

        wp_reset_postdata();
    }
?>

With the post_per_page i manage the entries per site. In while loop i build up the entries that should be showed.

Solution 3

There is no guarantee that your issue is WordPress related. However, because you haven't given a very general question, I am going to give you a very general answer. This should aid you in figuring out what is wrong and solving it yourself.

  1. Check out underscores. Download it and review the templates (like index.php, archive.php, etc.) to see if you're missing something that underscores includes. The nice thing about underscores is that it's all the basic stuff you need to create a running theme, with no frills. So, if it's there and not in your code, it may be worth exploring. Take special care for any code blocks relating to have_posts.

  2. It may not actually be anything wrong with your theme. Try testing another theme (say, underscores, which you've conveniently downloaded) to see if it has pagination working and intact. If it does, then, you're in luck... That means you just have to dig a bit deeper to reconcile what's wrong with your code that's right with underscores.

  3. If you've discovered that it's not something wrong with your theme but in fact something wrong with your server configuration, that's also something of a relief, in a matter of speaking. It means that you should theoretically be able to test your installation somewhere else, or reinstall your server, and make it work. Before going that far, try to simply reinstall your version of WordPress. Who knows... It could work.

Solution 4

You should pass the "page"/"paged" var in the query_post function:

if ( get_query_var('paged') ) {
 $paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
 $paged = get_query_var('page');
} else {
 $paged = 1;
}
query_posts(array('paged' => $paged));
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
<!--Your HTML-->.
<?php endwhile; endif;  wp_reset_query(); ?>
Share:
18,203
cpcdev
Author by

cpcdev

I am the owner of Active Technologies

Updated on June 04, 2022

Comments

  • cpcdev
    cpcdev almost 2 years

    I'm still stuck on this issue..

    The pagination on my WordPress blog is not working - http://www.example.com/news

    When you click a different page number it updates the URL (and page title) correctly but it does not show different posts.

    Ive tried:

    • Disabling all plug-ins
    • Changing the permalink structure
    • Changing the number of blog posts displayed in Settings>Reading
    • Changing http://www.example.com/recall-news to a different path to avoid conflicting with a post category named "news"

    Nothing has worked for me.

    I've seen many solutions for a custom query, but I'm using the posts page that you set in Settings>Reading>Posts Page so I did not write any code to display the posts on this page.

    • What WordPress file do I modify to fix the blog pagination in this case? I'm guessing I can add something to functions.php, but I haven't found a solution yet.

    UPDATE: I have not found the solution yet. I know I can do it by writing my own query but I want to stick with the default WP blog.

  • cpcdev
    cpcdev over 8 years
    Sorry? Can you expand on that for me?
  • Hans Koch
    Hans Koch over 8 years
    why a plugin for a default pagination ? the_posts_pagination() or get_the_posts_pagination() are already aviable from core also paginate_links().
  • OpenWebWar
    OpenWebWar over 8 years
    More plugins > increase page load and db fetch ... So max use wp core methods if possible ...