[英]Wordpress category.php page pagination showing 404 page
在category.php页面中,默认帖子是通过某些类别显示的,具有分页功能,并且从永久链接设置的网址中删除了“类别”。
不幸的是,它在分页到第二页时重定向到404页。
我什至尝试在wordpress default 2015主题中检查类别分页,它也无法在其中使用。
这是我的category.php,仅带有wordpress循环进行测试。
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title();
endwhile;
endif;
next_posts_link( 'Older posts' );
previous_posts_link( 'Newer posts' );
注意:如果未从URL中删除类别,则一切正常。
http://www.domain.com/category/my_category/page/2 (works)
http://www.domain.com/my_category/page/2 (doesnt work)
我需要添加/修改任何东西才能使其正常工作吗?
这是正常现象,请尝试使用以下代码:
add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules' );
function vipx_filter_category_rewrite_rules( $rules ) {
$categories = get_categories( array( 'hide_empty' => false ) );
if ( is_array( $categories ) && ! empty( $categories ) ) {
$slugs = array();
foreach ( $categories as $category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
if ( 0 == $category->category_parent ) {
$slugs[] = $category->slug;
} else {
$slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
}
}
}
if ( ! empty( $slugs ) ) {
$rules = array();
foreach ( $slugs as $slug ) {
$rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')(/page/(\d+)/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}
重要编辑:分页中存在错误,第10页以上的页面无法正常工作。
现在已修复: (\\d)+
更改为(\\d+)
。
希望这会有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.