我对自定义帖子类型分类法分页有疑问。 分页检索的页面数是正确的,但是当我单击第2页,第3页等时,我会看到第404页
我阅读了许多有关如何解决此问题的文章,但是没有人为我工作。
赞:
Pagination with Custom Post Type and Taxonomies return 404
Custom taxonomy and custom post type with custom pagination 404 not found
https://jewelfarazi.me/fix-wordpress-custom-taxonomy-pagination-404-error/
还有许多其他
有我的密码
CPT分类代码:
function registerAlbo_categoryTaxonomy()
{
register_taxonomy(
'albo_category',
'albo',
[
'labels' => [
'name' => __('Albo category', PLUGIN_SLUG),
'singular_name' => __('Albo category', PLUGIN_SLUG),
'menu_name' => __('Albo category', PLUGIN_SLUG),
'all_items' => __('All Albo category', PLUGIN_SLUG),
'parent_item' => __('Parent Albo category', PLUGIN_SLUG),
'parent_item_colon' => __('Parent Albo category:', PLUGIN_SLUG),
'new_item_name' => __('New Albo category name', PLUGIN_SLUG),
'add_new_item' => __('Add new Albo category', PLUGIN_SLUG),
'edit_item' => __('Edit Albo category', PLUGIN_SLUG),
'update_item' => __('Update Albo category', PLUGIN_SLUG),
'view_item' => __('View Albo category', PLUGIN_SLUG),
'separate_items_with_commas' => __('Separate Albo category with commas', PLUGIN_SLUG),
'add_or_remove_items' => __('Add or remove Albo category', PLUGIN_SLUG),
'choose_from_most_used' => __('Choose from the most used', PLUGIN_SLUG),
'popular_items' => __('Popular Albo category', PLUGIN_SLUG),
'search_items' => __('Search Albo category', PLUGIN_SLUG),
'not_found' => __('Not Found', PLUGIN_SLUG),
'no_terms' => __('No Albo category', PLUGIN_SLUG),
'items_list' => __('Albo category list', PLUGIN_SLUG),
'items_list_navigation' => __('Albo category list navigation', PLUGIN_SLUG)
],
'hierarchical' => TRUE,
'show_admin_column' => TRUE,
'exclude_from_search' => FALSE,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => [
'slug' => 'albo-category',
'with_front' => FALSE
]
]
);
}
循环和分页代码
<?php $qobj = get_queried_object(); ?>
<?php $term_id = $qobj->term_id; ?>
<?php $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; ?>
<?php
$the_query = new WP_Query([
'post_type' => 'albo',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 2,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'albo_category',
'field' => 'term_id',
'terms' => $term_id
)
)
]);
?>
<?php if($the_query->have_posts()): ?>
<?php while($the_query->have_posts()): ?>
<?php $the_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>
<div class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $the_query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => true,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => false,
'add_args' => false,
'add_fragment' => '',
) );
?>
</div>
上面的代码,如果我每页总共有6个帖子和2个帖子,则分页检索我3页,但是当我单击“不起作用”并给我404时。
我不明白为什么这行不通。我想念什么吗?
谢谢