新闻中心

WordPress文章列表分页提示404的解决办法

作者 / 无忧主机 时间 2013-10-15 16:25:20

无忧主机小编自诩对wordpress还是比较了解的。但在这几天建立一个小企业网站的过程中,有个问题足足困扰了小编一晚上。且听小编细细道来。 在大框架都处理的差不多了之后,小编开始在各个栏目中发表文章。开始小编发现这样一个现象:在发表的文章数量到达第2页的时候,点击第2页,显示找不到网页(提示 http 404)。小编感到很奇怪,又来到后台查看了一下,文章确实存在。所以对此小编并没有很在意。在小编发表完成所有几十篇文章之后,第2页没有问题了。但是小编发现,总共6页条目的文章中,前5页都可以正常显示,唯独第6页提示找不到网页(404)。也就是说,无论小编发表多少篇文章,最后一页的文章都无法显示。同时,我也看了同服务器上其它php虚拟主机,安装wordpress的都运行的良好,也没遇到我这倒霉问题。 一开始,小编以为是wodpress固定链接(伪静态)的问题。在尝试了取消固定链接,用wordpress默认链接的操作之后,问题依旧。 在折腾了一个晚上并且向度娘求助无数次之后,小编无意中发现了一篇文章,试过之后问题竟然得到了解决。解决方法如下: 打开目录下wp-includes\class-wp.php 这个文件,要找到function handle_404()这个函数,原代码如下: function handle_404() { global $wp_query;   // If we've already issued a 404, bail. if ( is_404() ) return;   // Never 404 for the admin, robots, or if we found posts. if ( is_admin() || is_robots() || $wp_query->posts ) { status_header( 200 ); return; }   // We will 404 for paged queries, as no posts were found. if ( ! is_paged() ) {   // Don't 404 for these queries if they matched an object. if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() ) { status_header( 200 ); return; }   // Don't 404 for these queries either. if ( is_home() || is_search() ) { status_header( 200 ); return; } }   // Guess it's time to 404. $wp_query->set_404(); status_header( 404 ); nocache_headers(); }   将其替换为如下代码并删除 && !is_paged()  注意备份。   function handle_404() { global $wp_query; if ( !is_admin() && ( 0 == count( $wp_query->posts ) ) && !is_404() && !is_robots() && !is_search() && !is_home() ) { // Don't 404 for these queries if they matched an object. if ( ( is_tag() || is_category() || is_tax() || is_author() ) && $wp_query->get_queried_object() && !is_paged() ) { if ( !is_404() ) status_header( 200 ); return; } $wp_query->set_404(); status_header( 404 ); nocache_headers(); } elseif ( !is_404() ) { status_header( 200 ); } } 通过以上方法,小编的问题得到了解决。小编对代码盲~以上代码是做了什么修改,小编也不明白。但是小编通过一晚上询问度娘发现,这样的问题,好像在很多主题中都存在。如果您遇到了这样的问题,可以用小编的这个方法解决,也不至于像小编这样纠结一晚上了~

本文地址:https://www.51php.com/wordpress/12859.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服