我已经从自定义帖子类型“厨房”中创建了一个自定义分类法“厨房”,但是在打开页面时出现分页错误404。
add_action( 'init', 'rt_create_taxonomy_kitchens', 0 );
function rt_create_taxonomy_kitchens() {
$args = array(
'label' => _x( 'Kitchens', 'taxonomy general name' ),
'labels' => array(
...
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_in_quick_edit' => true,
'meta_box_cb' => null,
'show_admin_column' => false,
'description' => '',
'hierarchical' => true,
'update_count_callback' => '',
'query_var' => true,
'rewrite' => array(
'slug' => 'kitchens',
'with_front' => false,
'hierarchical' => true,
'ep_mask' => EP_NONE,
),
'sort' => null,
'_builtin' => false,
);
register_taxonomy( 'kitchens', array( 'kitchen' ), $args );
}
add_action( 'init', 'rt_register_post_kitchen', 0 );
function rt_register_post_kitchen() {
$args = array(
'label' => _x( 'Kitchens', 'Post Type General Name', 'text_domain' ),
'labels' => array(
...
),
'description' => '',
'public' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-editor-textcolor',
'map_meta_cap' => null,
'hierarchical' => false,
'supports' => array(
...
),
'register_meta_box_cb' => null,
'taxonomies' => array( 'kitchens' ),
'has_archive' => false,
'rewrite' => array(
'slug' => 'kitchen',
'with_front' => false,
'feeds' => false,
'pages' => true,
),
'permalink_epmask' => EP_PERMALINK,
'query_var' => true,
'can_export' => true,
'delete_with_user' => null,
'show_in_rest' => false,
'rest_base' =>'kitchen',
'_builtin' => false,
);
register_post_type( 'kitchen', $args );
}
add_filter( 'term_link', 'rt_taxonomy_link', 10, 3 );
function rt_taxonomy_link( $link, $term, $taxonomy ) {
if ( $taxonomy !== 'kitchens' ) return $link;
$pos = strpos($link, 'kitchens/');
return $pos !== false ? substr_replace($link, '', $pos, strlen('kitchens/')) : $link;
// return str_replace( 'kitchens/', '', $link );
}
add_action('init', 'rt_taxonomy_rewrite_rule');
function rt_taxonomy_rewrite_rule() {
add_rewrite_rule('kitchens/?$', 'index.php?kitchens=kitchens', 'top');
}
当我尝试转到第二页时,它仅显示404页错误。 我如何添加分页,请提供帮助。
答案 0 :(得分:0)
SaveChangesAsync