我创建了一个名为“portfolio”的自定义帖子类型和一个名为“portfolio categorie”的自定义分类法。虽然我在页面中看到了新的类别,但我在从url结构中删除“front”时遇到了一个问题。我的首选url是domain.com/portfolio/category-name/
或domain.com/portfolio/categorie/catergory-name
也是一种选择。
在我的永久链接设置中,我将此作为一种结构(用于博客):/blog/%postname%/
当我访问自定义分类类别页面时,我会看到一个404错误页面。我确实重写了permalinks。
如果我将with\\U front更改为\'with_front\' => false
WordPress返回带有url的页面/blog/portfolio/portfolio-name/
我做错了什么?
迄今为止我的代码:
function custom_post_type() {
$labels = array(
\'name\' => _x( \'Portfolio\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Project\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Portfolio\', \'text_domain\' ),
\'name_admin_bar\' => __( \'Portfolio\', \'text_domain\' ),
\'archives\' => __( \'Item Archives\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Item:\', \'text_domain\' ),
\'all_items\' => __( \'Alle Projecten\', \'text_domain\' ),
\'add_new_item\' => __( \'Voeg nieuw Project toe\', \'text_domain\' ),
\'add_new\' => __( \'Voeg toe\', \'text_domain\' ),
\'new_item\' => __( \'Nieuw Project\', \'text_domain\' ),
\'edit_item\' => __( \'Bewerk Project\', \'text_domain\' ),
\'update_item\' => __( \'Pas Project aan\', \'text_domain\' ),
\'view_item\' => __( \'Bekijk Project\', \'text_domain\' ),
\'search_items\' => __( \'Doorzoek Project\', \'text_domain\' ),
\'not_found\' => __( \'Niet gevonden\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Niet gevonden in de prullenmand\', \'text_domain\' ),
\'featured_image\' => __( \'Project Hoofdafbeelding\', \'text_domain\' ),
\'set_featured_image\' => __( \'Stel Hoofdafbeelding in\', \'text_domain\' ),
\'remove_featured_image\' => __( \'Verwijder hoofdafbeelding\', \'text_domain\' ),
\'use_featured_image\' => __( \'Gebruik als hoofdafbeelding\', \'text_domain\' ),
\'insert_into_item\' => __( \'Voeg toe aan project\', \'text_domain\' ),
\'uploaded_to_this_item\' => __( \'Geupload naar dit project\', \'text_domain\' ),
\'items_list\' => __( \'Project lijst\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Project navigatie\', \'text_domain\' ),
\'filter_items_list\' => __( \'Filter project lijst\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'Portfolio\', \'text_domain\' ),
\'description\' => __( \'Recente projecten\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-images-alt\',
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
\'rewrite\' => array( \'with_front\' => false ),
);
register_post_type( \'portfolio\', $args );
}
add_action( \'init\', \'custom_post_type\', 0 );
function portfolio_custom_taxonomy() {
$labels = array(
\'name\' => _x( \'Categorieën\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Categorie\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Zoek categorieën\' ),
\'all_items\' => __( \'Alle categorieën\' ),
\'parent_item\' => __( \'Bovenliggende categorie\' ),
\'parent_item_colon\' => __( \'Bovenliggende categorie:\' ),
\'edit_item\' => __( \'Bewerk categorie\' ),
\'update_item\' => __( \'Update categorie\' ),
\'add_new_item\' => __( \'Nieuwe categorie toevoegen\' ),
\'new_item_name\' => __( \'Nieuwe categorie\' ),
\'menu_name\' => __( \'Categorieën\' ),
);
register_taxonomy(\'portfolio-categorie\', \'portfolio\', array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'portfolio\', \'with_front\' => false ),
));
}
add_action( \'init\', \'portfolio_custom_taxonomy\', 0 );
任何帮助都将不胜感激!