Anonymous
Пользовательские таксономии Wordpress и пользовательский тип сообщения – не работает нумерация страниц
Сообщение
Anonymous » 11 окт 2024, 08:10
Я создал пользовательскую таксономию «кухни» в форме пользовательского типа сообщения «кухня», но нумерация страниц не работает, при открытии страницы появляется ошибка 404.
'kitchens/built-in/2' – не работает.
'kitchens/built-in/page/2' – не работает.
Код: Выделить всё
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.
Как добавить нумерацию страниц, помогите.
Подробнее здесь:
https://stackoverflow.com/questions/536 ... pagination
1728623425
Anonymous
Я создал пользовательскую таксономию «кухни» в форме пользовательского типа сообщения «кухня», но нумерация страниц не работает, при открытии страницы появляется ошибка 404. [list][*]'kitchens/built-in/2' – не работает. [*]'kitchens/built-in/page/2' – не работает.[/list] [code]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 ); } [/code] [code] 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 ); } [/code] [code]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'); } [/code] Когда я пытаюсь перейти на вторую страницу, мне просто выдается ошибка 404. Как добавить нумерацию страниц, помогите. Подробнее здесь: [url]https://stackoverflow.com/questions/53695800/wordpress-custom-taxonomies-and-custom-post-type-not-working-pagination[/url]