首先是问题,然后是尝试。
问题是如果我访问的是另一个页面而不是第一个类别页面,我会收到404 NOT FOUND错误。 在类别页面上,我有一个正常的分页。第一个网站工作。 (http://mypage.com/category/properties)
点击“下一页”按钮后,我在页面http://mypage.com/category/properties/page/2上,得到错误404 NOT FOUND。
但为什么?
首先我尝试了这个问题Custom Post Type and Taxonomy pagination 404 error,但exclude_from_search
和以下查询无效。
我也试过这个。 http://wordpress.org/support/topic/one-again-page-not-found-on-second-and-further-pages 但是query_posts尝试与WP_Query尝试的结果相同。
我也尝试过使用预查询的事件。但问题是相同的 - .-
<?php
/* /srv/www/mypage/wp-content/themes/twentythirteen/category-1.php */
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array_merge($wp_query->query, array(
'posts_per_page' => 4,
'post_type' => 'property',
'post_status' => 'publish',
'meta_key' => 'property_typ',
'meta_value' => 'Rent',
'category_name' => null
));
$wp_query = new WP_Query($args);
echo '<ul>';
while (have_posts())
{
the_post();
echo '<li><a href="' . get_permalink(get_the_id()) . '">'
. get_the_title() . '</a></li>';
}
echo '</ul>';
echo paginate_links(array(
'base' => str_replace(99999, '%#%', esc_url(get_pagenum_link(99999))),
'total' => $wp_query->max_num_pages,
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged'))
));
Page 1
第2页
答案 0 :(得分:2)
尝试更改pre_get_posts过滤器。
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'property'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
在http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/
找到了这个答案 1 :(得分:0)
试试这个,它应该有效。还有类似问题
<?php
// Display pagination
global $wp_query;
$pagination_args = array(
'base' => '%_%',
'format' => '?' . $query_string . '&paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'type' => 'array'
);
$pagination = paginate_links($pagination_args);
$big = 999999999; // need an unlikely integer
$links .= paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?' . $query_string . '&paged=%#%&keyword='.$keyword,
'current' =>max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
echo $links;
?>
答案 2 :(得分:0)
我的自定义分类后分页遇到了同样的问题。较旧的帖子页面未找到404页面。此问题与WP分类标准有关,因此您必须重写自定义帖子类型分类法的规则,如下所示:
#include<iostream>
using namespace std;
int main(){
int month,day,year;
char symbol;
do{
cout<<"Enter date: ";
cin>>month>>symbol>>day>>symbol>>year;
if(symbol=='/'&&month<=05&&day<=31&&year==2016){
cout<<month<<symbol<<day<<symbol<<year;
if(month==01){ // this code is for month of January
if(day==3||day==10||day==17||day==24||day==31){
cout<<" is Sunday.";
}
else if(day==4||day==11||day==18||day==25){
cout<<" is Monday.";
}
else if(day==5||day==12||day==19||day==26){
cout<<" is Tuesday.";
}
else if(day==6||day==13||day==20||day==27){
cout<<" is Wednesday.";
}
else if(day==7||day==14||day==21||day==28){
cout<<" is Thursday.";
}
else if(day==1||day==8||day==15||day==22||day==29){
cout<<" is Friday.";
}
else if(day==2||day==9||day==16||day==23||day==30){
cout<<" is Saturday.";
}
}
else if(month==02){ //this code is for month of February
if(day==7||day==14||day==21||day==28){
cout<<" is Sunday.";
}
else if(day==1||day==8||day==15||day==22||day==29){
cout<<" is Monday.";
}
else if(day==2||day==9||day==16||day==23){
cout<<" is Tuesday.";
}
else if(day==3||day==10||day==17||day==24){
cout<<" is Wednesday.";
}
else if(day==4||day==11||day==18||day==25){
cout<<" is Thursday.";
}
else if(day==5||day==12||day==19||day==26){
cout<<" is Friday.";
}
else if(day==6||day==13||day==20||day==27){
cout<<" is Saturday.";
}
}
else if(month==03){ //this code is for month of March
if(day==6||day==13||day==20||day==27){
cout<<" is Sunday.";
}
else if(day==7||day==14||day==21||day==28){
cout<<" is Monday.";
}
else if(day==1||day==18||day==15||day==22||day==29){
cout<<" is Tuesday.";
}
else if(day==2||day==9||day==16||day==23||day==30){
cout<<" is Wednesday.";
}
else if(day==3||day==10||day==17||day==24||day==31){
cout<<" is Thursday.";
}
else if(day==4||day==11||day==18||day==25){
cout<<" is Friday.";
}
else if(day==5||day==12||day==19||day==26){
cout<<" is Saturday.";
}
}
else if(month==04){ //this code is for month of April
if(day==3||day==10||day==17||day==24){
cout<<" is Sunday.";
}
else if(day==4||day==11||day==18||day==25){
cout<<" is Monday.";
}
else if(day==5||day==12||day==19||day==26){
cout<<" is Tuesday.";
}
else if(day==6||day==13||day==20||day==27){
cout<<" is Wednesday.";
}
else if(day==7||day==14||day==21||day==28){
cout<<" is Thursday.";
}
else if(day==1||day==8||day==15||day==22||day==29){
cout<<" is Friday.";
}
else if(day==2||day==9||day==16||day==23||day==30){
cout<<" is Saturday.";
}
}
else if(month==05){ //this code is for month of May
if(day==1||day==8||day==15|day==22||day==29){
cout<<" is Sunday.";
}
else if(day==2||day==9||day==16||day==23||day==30){
cout<<" is Monday.";
}
else if(day==3||day==10||day==17||day==24||day==31){
cout<<" is Tuesday.";
}
else if(day==4||day==11||day==18||day==25){
cout<<" is Wednesday.";
}
else if(day==5||day==12||day==19||day==26){
cout<<" is Thursday.";
}
else if(day==6||day==13||day==20||day==27){
cout<<" is Friday.";
}
else if(day==7||day==14||day==21||day==28){
cout<<" is Saturday.";
}
}
break;
}
else{
cout<<"You have entered an invalid input.\n"<<endl;
}
}while(symbol!='/'&&!(month<=05)&&!(day<=31)&&year!=2016);
return 0;
}
这适用于所有自定义帖子类型分类,只使用默认查询循环而不传递任何参数。页面将基于常规生成 - &gt;读数。