wordpress主循环会按照url中的page这个参数来自动分页数据,但是如果你的page值超出了主循环拥有的数据量,就会被定义到404页面去。在自己的页面写的代码也不会被加载。
想要自己的页面接收到page参数,就要在加载404页面之前跳转到自己的页面去。
在template-loader.php里,加载模板之前会有一个筛选行为,我们可以在这上面做文章。下面是template-loader.php里的几行代码,看看就可以了,不要改动。
if ( $template = apply_filters( 'template_include', $template ) )
include( $template );
return;
在自己主题的functions.php 里 ,给template_include加一个函数‘’change404ToCategory”(这里是我自己定义的函数名,各位可以随意定),下面是代码:
add_filter('template_include','change404ToCategory');
function change404ToCategory($template){//exit();
global $wp_query;
$wp_query->is_category = true;
$wp_query->is_404 = false;
if(is_category('xxxx')){
$template = get_category_template();
}
return $template;
}
<