duandie5707 2019-02-07 20:25
浏览 93

Wordpress自定义帖子类型归档分页导致404错误

Whenever I try to access another page using the archive's pagination I get a 404 error. Apparently a well known problem but so far no solution has worked in my case. I might have been applying it wrong though.

Following advice I found online and in the codex I currently have the archive page template set up for a custom post-type like so:

$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

$args = array(
    'post_type' => 'application',
    'posts_per_page' => 2,
    'paged' => $paged
);

$query = new WP_Query($args);

if ($query->have_posts()) { ?>

    <div class="posts">
        <!-- THE POSTS -->
    </div>

    <?php
    $big = 999999999; // unlikely integer

    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'prev_next'    => true,
        'prev_text'    => sprintf( '<i></i> %1$s', __( 'Previous', 'textdomain' ) ),
        'next_text'    => sprintf( '%1$s <i></i>', __( 'Next', 'textdomain' ) ),
        'current' => max( 1, get_query_var('paged') ),
        'total' => $query->max_num_pages
    ) );

    wp_reset_postdata();

} ?>

and have my permalinks set to /%category%/%postname%/. I understand this could be part of the problem.

And this is where I kind of get lost. What am I doing wrong? Any help would be very much appreciated.

  • 写回答

1条回答 默认 最新

  • doupu0619 2019-02-07 22:04
    关注

    I would change the first line to:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1 ?>
    

    Also adding this line after that first line might help:

    $number_of_posts = get_option('posts_per_page', 2);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看