今天上来,才发现我的写的分页。当时测试的时候好好,可以正常翻页。
病状:前2页翻没有问题,翻第三页的时候,啊,空白…(这种怪毛病,让人抓狂)
我又对着代码,一步一步测试。我靠,居然找不到到底哪里出错了。无奈啊,只有到网上找找。经过漫长的时间,终于找到了方法(发觉资源挺少,也不好搜搜)。
打开wp-includes\class-wp.php文件找到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
| 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();
}
|
修改为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| 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()) {
if ( !is_404() )
status_header( 200 );
return;
}
$wp_query->set_404();
status_header( 404 );
nocache_headers();
}elseif( !is_404() ) {
status_header( 200 );
}
}
|
经测试有效,对老版本的修改:
打开wp-includes\class.php文件找到handle_404,与上面同样的内容修改为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| 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 );
}
}
|
我没有测试,自己测试吧。