就在刚才发现了我的个人博客网站上存在的一个问题,之前的分页一直好好的,今天竟然莫名其妙的出问题了,从第二页之后的所有分页都提示404错误,找不到页面,但是参数也传过来了,试了别的分页还是不行,都是一样的问题。在本地服务器代码改好了,可以正常显示分页了,但一上传到网上,原来的问题还是存在。
这下可是没辙了,于是找百度,寻求各种方法,终于看到一篇文章,按照上边的方法,把我的问题解决了。一是,害怕自己有一天还会遇到同样的问题,二是,如果还有小伙伴遇到和我一样的问题,可以帮助到大家,我现在把解决方法记录在这里,以便以后查找。解决方法如下:
打开目录下wp-includes\class-wp.php 这个文件,要找到function handle_404()这个函数,原代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| public 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 ) {
$success = true;
if ( is_singular() ) {
$p = false;
if ( $wp_query->post instanceof WP_Post ) {
$p = clone $wp_query->post;
}
// Only set X-Pingback for single posts that allow pings.
if ( $p && pings_open( $p ) ) {
@header( 'X-Pingback: ' . get_bloginfo( 'pingback_url' ) );
}
// check for paged content that exceeds the max number of pages
$next = '<!--nextpage-->';
if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $this->query_vars['page'] ) ) {
$page = trim( $this->query_vars['page'], '/' );
$success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 );
}
}
if ( $success ) {
status_header( 200 );
return;
}
}
// We will 404 for paged queries, as no posts were found.
if ( ! is_paged() ) {
// Don't 404 for authors without posts as long as they matched an author on this site.
$author = get_query_var( 'author' );
if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
status_header( 200 );
return;
}
// Don't 404 for these queries if they matched an object.
if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
status_header( 200 );
return;
}
// Don't 404 for these queries either.
if ( is_home() || is_search() || is_feed() ) {
status_header( 200 );
return;
}
}
// Guess it's time to 404.
$wp_query->set_404();
status_header( 404 );
nocache_headers();
} |
改成以下代码并删除 && !is_paged() 注意备份。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| 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 );
}
} |
我通过上边的方法解决了分页显示404的问题,如果谁有同样的问题,那就可以使用这个方法解决了,不用像我烦恼了一晚上。
「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」
共 0 条评论关于"解决文章列表分页提示404错误_wordpress"
最新评论