简体   繁体   English

Wordpress 下一页/上一页链接在第二页时不起作用

[英]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. 尝试对自定义WP_Query使用“ paged”参数。 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 您也可以尝试使用“ post_per_page”参数

     <?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 或者您可以使用plugin =)例如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/我也有这个问题,我想创建一个帖子,在我的博客文章中继续显示下一个和上一个按钮, 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.但是很遗憾,尽管我使用的是免费版本,但尽管使用了 Theia Post Slider,它还是没有显示出来。

Is there any free plugin for blog post slider?有没有免费的博客帖子滑块插件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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