【问题标题】:Page 2 not found (404) Wordpress Pagination未找到第 2 页 (404) Wordpress 分页
【发布时间】:2018-01-10 14:27:45
【问题描述】:

我在 localhost 中测试 WordPress,发布文章以查看如何工作,一切都很好,直到我不得不在一页中有很多文章,我不得不使用分页转到第二页,然后我点击了第二页,但我得到了一个 404 Not Found 页面。

我找了大约 2-3 个小时,尝试了每个函数,每个示例,但结果都是一样的。

首页为静态首页,称为Landing,所有文章均设置为Blog页面。

我的 index.php 中的 php 代码:

<div class="container-medium">
    <div class="row">


        <?php while(have_posts()) : the_post(); ?>
        <div class="col-xs-12 col-sm-12 col-md-12">
            <?php the_post_thumbnail('post-thumbnail', array( 'class'   => "img-responsive desaturate attachment-post-thumbnail")); ?> 
            <h3 class="blog-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <div class="row">
                <div class="col-sm-12"><p class="blog-post-text"><?php echo get_excerpt(); ?></p></div>
                <div class="col-sm-12"><a class="btn btn-sm btn-readmore" href="<?php echo get_permalink(); ?>">Read more <i class="icon-right-open"></i></a></div>
            </div>
        <hr class="dotted">
    </div>


    <?php endwhile; wp_reset_query(); ?>
    </div> <!-- end .row -->
            <?php if ( have_posts() ) : ?>

    <!-- Add the pagination functions here. -->

    <!-- Start of the main loop. -->
    <?php while ( have_posts() ) : the_post();  ?>

    <!-- the rest of your theme's main loop -->

    <?php endwhile; ?>
    <!-- End of the main loop -->

    <!-- Add the pagination functions here. -->

    <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

    <?php else : ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

</div> <!-- end .container-medium -->

我阅读了一堆类似的问题,但没有得到我想要的结果。

谢谢!

PS:PHP初学者

【问题讨论】:

    标签: php wordpress pagination


    【解决方案1】:

    在while循环上面写这个

    <?php
    
    
        $post_query = query_posts(array(
        'post_type'      => 'cover', // You can add a custom post type if you like
        'paged'          => get_query_var('paged', 1),
        'posts_per_page' => 1
    ));
    
    ?>
    

    在底部

      <?php
    
      global $wp_query;
    
      $big = 999999999; // need an unlikely integer
    
      echo paginate_links( array(
           'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
           'format' => '?paged=%#%',
           'current' => max( 1, get_query_var('paged') ),
           'total' => $wp_query->max_num_pages
       ) );
    
      ?>
    

    【讨论】:

    • 我尝试更改永久链接,并使用默认结构 (website.com/?p=123)。我会试一试。谢谢
    • 不工作,只显示分页,但帖子不见了。
    • 在您的 localhost 重写模式中是关闭的,这就是为什么只有永久链接的默认结构在工作......将重写模式更改为 on
    猜你喜欢
    • 1970-01-01
    • 2014-07-12
    • 2014-10-16
    • 1970-01-01
    • 2018-06-22
    • 2020-11-22
    • 2014-03-24
    • 1970-01-01
    相关资源
    最近更新 更多