页面内分类链接,如使用get_category_link()
仍然附加/niche/
URL的前缀,也就是404我觉得我快要找到我需要的东西了,但这似乎超出了我的能力,这让我很难过。非常感谢!我的代码块:
function cptui_register_my_cpts_review() {
/**
* Post Type: Reviews.
*/
$labels = array(
"name" => __( "Reviews", "" ),
"singular_name" => __( "Review", "" ),
"menu_name" => __( "Mes Reviews", "" ),
"all_items" => __( "Toutes les Reviews", "" ),
"add_new" => __( "Ajouter une Review", "" ),
"add_new_item" => __( "Ajouter une Review", "" ),
"edit_item" => __( "Modifier la Review", "" ),
"new_item" => __( "Nouvelle Review", "" ),
"view_item" => __( "Voir la Review", "" ),
"view_items" => __( "Voir les Reviews", "" ),
"search_items" => __( "Rechercher une Review", "" ),
"not_found" => __( "Pas de Review Trouvée", "" ),
"not_found_in_trash" => __( "Pas de Review Trouvée dans Corbeille", "" ),
"parent_item_colon" => __( "Review Parente", "" ),
"insert_into_item" => __( "Insérer dans la Review", "" ),
"uploaded_to_this_item" => __( "Insérer dans la Review", "" ),
"filter_items_list" => __( "Filtrer la Liste des Reviews", "" ),
"items_list_navigation" => __( "Navigation dans la Liste des Reviews", "" ),
"items_list" => __( "Liste des Reviews", "" ),
"attributes" => __( "Attributs de la Review", "" ),
"parent_item_colon" => __( "Review Parente", "" ),
);
$args = array(
"label" => __( "Reviews", "" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "%niche%", "with_front" => true ),
"query_var" => false,
"menu_icon" => "dashicons-awards",
"supports" => array( "title", "editor", "thumbnail", "excerpt", "custom-fields", "genesis-seo" ),
"taxonomies" => array( "niche" ),
);
register_post_type( "review", $args );
}
add_action( \'init\', \'cptui_register_my_cpts_review\' );
function cptui_register_my_taxes_niche() {
/**
* Taxonomy: Niches.
*/
$labels = array(
"name" => __( "Niches", "" ),
"singular_name" => __( "Niche", "" ),
"menu_name" => __( "Niches", "" ),
"all_items" => __( "Toutes les niches", "" ),
"edit_item" => __( "Modifier la niche", "" ),
"view_item" => __( "Voir la niche", "" ),
"update_item" => __( "Mettre à jour le nom de la niche", "" ),
"add_new_item" => __( "Ajouter nouvelle niche", "" ),
"new_item_name" => __( "Nom de la nouvelle niche", "" ),
"parent_item" => __( "Niche parente", "" ),
"parent_item_colon" => __( "Niche parente :", "" ),
"search_items" => __( "Rechercher les niches", "" ),
"popular_items" => __( "Niches Populaires", "" ),
"separate_items_with_commas" => __( "Séparer les niches avec des virgules", "" ),
"add_or_remove_items" => __( "Ajouter ou enlever des Niches", "" ),
"choose_from_most_used" => __( "Choisir parmi les plus utilisées", "" ),
"not_found" => __( "Pas trouvé !", "" ),
"no_terms" => __( "Pas de niches", "" ),
"items_list_navigation" => __( "Navigation par liste des niches", "" ),
"items_list" => __( "Liste des niches", "" ),
);
$args = array(
"label" => __( "Niches", "" ),
"labels" => $labels,
"public" => true,
"hierarchical" => true,
"label" => "Niches",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( \'slug\' => \'niche\', \'with_front\' => false, \'hierarchical\' => false ),
"show_admin_column" => false,
"show_in_rest" => false,
"rest_base" => "",
"show_in_quick_edit" => true,
);
register_taxonomy( "niche", array( "review" ), $args );
}
add_action( \'init\', \'cptui_register_my_taxes_niche\' );
function wpse_5308_post_type_link( $link, $post ) {
if ( $post->post_type === \'review\' ) {
if ( $terms = get_the_terms( $post->ID, \'niche\' ) )
$link = str_replace( \'%niche%\', current( $terms )->slug, $link );
}
return $link;
}
add_filter( \'post_type_link\', \'wpse_5308_post_type_link\', 10, 2 );