1

Symptoms

Visiting /blog/ loads the first 10 posts, as expected.

Visiting /blog/page/2/ (and onward) loads the new URL but with the same 10 posts. Nothing changes but the URL.

Setup Details

Custom Permalink Structure: /blog/%year%/%monthnum%/%day%/%postname%/

Static Posts Page: "Blog" (slug of 'blog')

I'm using home.php to displays posts with the following markup:

<?php
/**
 * The archive for blog posts 
*/

get_header(); ?>

    <div id="main-content">
        <div class="container">

            <section id="content" class="blog"> 

                <?php while ( have_posts() ) : the_post(); ?>

                    <?php get_template_part( 'content', 'blog-index' ); ?>

                <?php endwhile; ?>

            </section>

            <?php get_sidebar( 'blog' ); ?>

            <div class="pagination">
                <?php wp_pagenavi(); ?>
            </div>

        </div>
    </div>

<?php get_footer(); ?>

I've checked for plugin conflicts and I am running a relatively minimalistic setup. I'm using WP-PageNavi to generate the pagination.

I've also tried renaming the /blog/ page to 'blog2' with the thought that there might be a permalink conflict - same result. /blog2/page/2/ loads the same first 10 posts.

Any ideas what might be the cause here?

9
  • 1
    Does /blog/?paged=2 bring you to the second page of posts? If it doesn't work, then there is something screwing up the global WP_Query object. If it does work, then something is screwed up with the permalinks. Commented Feb 18, 2014 at 20:50
  • 2
    I've done some additional investigating and found out that the issue is related to my use of a custom class that strips out the "base slug" for a hierarchical post type. Here's referenced question and the code I'm using to do the stripping: wordpress.stackexchange.com/questions/114723/… Commented Sep 4, 2014 at 19:03
  • 2
    You should add your last comment as an edit to your question. Most people don't read comments, like me, I accidentally saw the comment :-) Commented Sep 5, 2014 at 6:52
  • 1
    Am I mistaken or has the problem you are having nothing to do with method the pagination links are generated? You might want to clarify that, because the answers are focusing on that. Additionally, can you confirm that the pagination works correctly, if you are not using the »strip out base slug«-code you mentioned? Furthermore, does the blog page show posts from the post type post or your CPT or both? Might be valuable to know. In short, it's probably a good idea to edit your question with the additional information needed. Commented Sep 6, 2014 at 12:50
  • 1
    I still don't get it why someone places a bounty on his own question and then simply abandons it, or just simply ignores/refuses to give proper details when asked for it by someone willing to help. Well, at the end of day, it is your reputation, waste it as you wish Commented Sep 8, 2014 at 16:00

5 Answers 5

0
$my_query = new WP_Query( array( 'posts_per_page' => 3, 'paged' => get_query_var('paged') ) );

while ( $my_query->have_posts() ) : $my_query->the_post();
    the_title();
    // more stuff here
endwhile;

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

wp_reset_postdata();

try this code and also increase the size of show posts in SETTINGS->Reading->Blog pages show at most 10 to 50 or 100, hope so it will help you.

3
0

Why are you using WP-PageNavi for number based pagination. WordPress offer a way to accomplish that. BTW here is the full query for you to use in home.php

<div id="main-content">
    <div class="container">

        <section id="content" class="blog"> 

            <?php

              if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; }

              $args = array(
                  'post_type' => 'post',
                  'paged' => $paged
              );

              $my_query = new WP_Query( $args );

              if ( $my_query->have_posts() ) :

                  while ( $my_query->have_posts() ) : $my_query->the_post();

                      get_template_part( 'content', 'blog-index' );

                  endwhile;

                  if ( $my_query->max_num_pages > 1 ) :
                      $big = 999999999;
                      echo '<div class="pagination">';
                      echo paginate_links( array(
                          'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                          'format' => '?paged=%#%',
                          'current' => max( 1, get_query_var('paged') ),
                          'total' => $my_query->max_num_pages
                      ) );
                      echo '</div>';
                  endif;

              else :

                    get_template_part( 'content', 'none' );

              endif;

              wp_reset_postdata();

            ?>

        </section>

        <?php get_sidebar( 'blog' ); ?>

    </div>
</div>
0

Please use this code I faced same problem then i implemented this

<?php if ( $wp_query->max_num_pages > 1 ) :?>
    <div class="pagination">
        <?php for ( $i = 1; $i <= $wp_query->max_num_pages; $i ++ ) { 
            $link = $i == 1 ? remove_query_arg( 'pg' ) : add_query_arg( 'pg', $i );
            echo '<a href="' . $link . '"' . ( $i == $paged ? ' class="active"' : '' ) . '>' . $i . '</a>';
        } ?>
    </div>
<?php endif ?>

Hope it helps you too.

0

Using home.php doesn't sound like a good idea, but if it is the only query in the page, you might have to add a couple of things. The following usually works for paginating a static page:

Add:

global $paged, $wp_query; 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

But you also have to add one more argument to your query arguments in your template part to enable pagination:

'paged'     => $paged

Your final code on the template would be:

get_header(); ?>

global $paged, $wp_query; 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    <div id="main-content">
        <div class="container">

        <section id="content" class="blog"> 

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'blog-index' ); ?>

            <?php endwhile; ?>

        </section>

        <?php get_sidebar( 'blog' ); ?>

        <div class="pagination">
            <?php wp_pagenavi(); ?>
        </div>

    </div>
</div>
-2

Why don't you force the pagination by adding the following code like so:

<div id="main-content">
    <div class="container">

        <section id="content" class="blog"> 

            <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            query_posts('posts_per_page=3&paged=' . $paged);
            ?>

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'blog-index' ); ?>

            <?php endwhile; ?>

        </section>

        <?php get_sidebar( 'blog' ); ?>

        <div class="pagination">
            <?php wp_pagenavi(); ?>
        </div>

    </div>
</div>

Check this link: http://codex.wordpress.org/Function_Reference/query_posts#Pagination

2
  • 1
    never use query_posts, and never run custom queries unnecessary Commented Sep 5, 2014 at 5:38
  • @PieterGoosen then Jonathan should add the loaded template part so that we see what is happening there.
    – aifrim
    Commented Sep 5, 2014 at 5:43

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