简体   繁体   中英

Wordpress next/previous page links not working when at the second page

I lost track when actually the pagination stopped working. Cannot even find the problem. This is frustrating. Here is the code:

<section class="content-section">

    <div class="col-md-10 col-md-offset-1">
        <?php
        if( have_posts() ):
        while( have_posts() ): the_post();
        get_template_part( 'template-parts/content', get_post_format() );
        endwhile;

        ?>
    </div>

    <div class="col-md-10 col-md-offset-1 text-center">
        <div class="blog-pagination">
            <?php
                next_posts_link('<span class="pagination-btn btn-center">Back</span>');
                previous_posts_link('<span class="pagination-btn">Next</span>');
            ?>
        </div>
    </div>
    <?php endif; ?>

</section>

The first page next takes to the second page but the previous page link doesn't appear and at the same time, if I hit next on the second page, it stays on the second page. Have got enough posts to paginate.

Try to use "paged" parameter with custom WP_Query. Something like :

<?php
       if (have_posts()) :
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
            'paged' => $paged
            );
        $loop = new WP_Query($args);
        while ($loop->have_posts()) : $loop->the_post();
        get_template_part( 'template-parts/content', get_post_format() );
        endwhile;
         ?>

    <div class="col-md-10 col-md-offset-1 text-center">
        <div class="blog-pagination">
            <?php
           next_posts_link('<span class="pagination-btn btn-center">Back</span>');
           previous_posts_link('<span class="pagination-btn">Next</span>'); 
          ?>
        </div>
    </div>
     <?php 
       wp_reset_postdata();
      endif; 
         ?>

Also you can try with "post_per_page" parameter

     <?php
       if (have_posts()) :
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
            'paged' => $paged
            'posts_per_page' => '10'

            );
        $loop = new WP_Query($args);
        while ($loop->have_posts()) : $loop->the_post();
        get_template_part( 'template-parts/content', get_post_format() );
        endwhile;
         ?>

   <div class="col-md-10 col-md-offset-1 text-center">
      <div class="blog-pagination">
        <?php
       next_posts_link('<span class="pagination-btn btn-center">Back</span>', $loop->max_num_pages);
       previous_posts_link('<span class="pagination-btn">Next</span>', $loop->max_num_pages); 
      ?>
     </div>
  </div>
  <?php 
   wp_reset_postdata();
  endif; 
     ?>

Or you can use plugin =) For example WP-PageNavi

I'm having issues with this as well, I want to create post that will keep showing next and previous button on my blog post here, https://gyonlineng.com/highest-paid-athletes-of-all-time/

But so sad that it's not showing despite using Theia Post Slider, although I'm using the free version.

Is there any free plugin for blog post slider?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM