解决 Wordpress分页导航出现的404错误

解决 Wordpress分页导航出现的404错误

一直没有发现首页的分页导航会出现404错误,上网参考了很多资料,最后找到解决办法

page404

 

这种情况,可以通过设置解决,但是不是非常的理想,设置办法:设置-->阅读-->博客页面至多显示   修改为1即可正常!

但是这种修改方式,可以解决首页的分页导航404,但是分类的文章只显示一条,然后就需要分页才可以查看其它的!

所以,最后通过修改函数的方式解决了!

注意:修改代码前,先备份原来的文件,便于恢复!!!谨记

旧版本:修改wordpress\wp-includes\classes.php

 

 

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 );
}
}

把上面代码中的 && !is_paged()删除掉即可

如果是新版本的wordpress,例如我的是3.8版本,则修改的文件为:wordpress\wp-includes\classe-wp.php

找到:

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();
}

把上面这个function的代码全部修改为上面的第一个function代码,然后删除 && !is_paged()即可

文章来源于网络或者作者投稿,若有侵权请联系删除,作者:老钟,如若转载,请注明出处:https://www.laoz.net/413.html

(0)
上一篇 2014 年 04 月 24 日
下一篇 2014 年 04 月 26 日

相关推荐