如何解决WORDPRESS分页导航出现的404错误

Data:01/03 07:20
2018
01/03
07:20
2018-01-03
A1-
通过修改wordpress\wp-includes\classes.php这个文件,在这个文件中找到function handle_404()这个函数,源代码如下:
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 );

}

}

A2-
将如上代码中的 && !is_paged() 这句删除即可解决问题【强烈建议:修改代码的时候最好备份原来的文件后,防止出错】
B1-
如果你是新版本的 wordpress ,你就要修改 wordpress\wp-includes\classe-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();

}

B2-
如果是这样的代码时,就把整个函数换成上面的第一个函数,然后删除 && !is_paged() 即可解决问题。
domainsworks

About domainsworks

  •