我在一个有许多CPT和自定义分类法的WP网站上工作,但也在该网站的常规博客部分使用常规的“post”帖子类型。
我希望博客帖子和归档以及类别在其永久链接中包含/blog/,但也希望为其他CPT指定永久链接结构,而不需要/blog/干扰。
例如:我有一个“events”CPT,它有一个名为“ecat”的自定义分类法。
现在我有了permalink的存档页sitename.com/events 工作正常
并且单事件页面具有permalink-likesitename.com/events/event-name 也
但自定义分类法存档位于sitename.com/ecat/ategory-name.我希望自定义分类法在其permalink中包含cpt slug,如:sitename.com/events/ecat/category-name
注意:我不希望单个事件的永久链接中包含分类术语。
我的CPT注册码:
$labels = array(
\'name\' => _x( \'Events\', \'Post Type General Name\', \'textdomain\' ),
\'singular_name\' => _x( \'Event\', \'Post Type Singular Name\', \'textdomain\' ),
\'menu_name\' => __( \'Events\', \'textdomain\' ),
\'name_admin_bar\' => __( \'Event\', \'textdomain\' ),
\'archives\' => __( \'Item Archives\', \'textdomain\' ),
\'attributes\' => __( \'Item Attributes\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent Item:\', \'textdomain\' ),
\'all_items\' => __( \'All Items\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New Item\', \'textdomain\' ),
\'add_new\' => __( \'Add New\', \'textdomain\' ),
\'new_item\' => __( \'New Item\', \'textdomain\' ),
\'edit_item\' => __( \'Edit Item\', \'textdomain\' ),
\'update_item\' => __( \'Update Item\', \'textdomain\' ),
\'view_item\' => __( \'View Item\', \'textdomain\' ),
\'view_items\' => __( \'View Items\', \'textdomain\' ),
\'search_items\' => __( \'Search Item\', \'textdomain\' ),
\'not_found\' => __( \'Not found\', \'textdomain\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'textdomain\' ),
\'featured_image\' => __( \'Featured Image\', \'textdomain\' ),
\'set_featured_image\' => __( \'Set featured image\', \'textdomain\' ),
\'remove_featured_image\' => __( \'Remove featured image\', \'textdomain\' ),
\'use_featured_image\' => __( \'Use as featured image\', \'textdomain\' ),
\'insert_into_item\' => __( \'Insert into item\', \'textdomain\' ),
\'uploaded_to_this_item\' => __( \'Uploaded to this item\', \'textdomain\' ),
\'items_list\' => __( \'Items list\', \'textdomain\' ),
\'items_list_navigation\' => __( \'Items list navigation\', \'textdomain\' ),
\'filter_items_list\' => __( \'Filter items list\', \'textdomain\' ),
);
$args = array(
\'label\' => __( \'Event\', \'textdomain\' ),
\'description\' => __( \'Events custom post type\', \'textdomain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-calendar-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\',
\'show_in_rest\' => false,
\'rewrite\' => array( \'slug\' => \'events\',\'with_front\' => false ),
);
register_post_type( \'events\', $args );
我的自定义分类注册代码:
//Event Categories
$labels = array(
\'name\' => _x( \'Events Categories\', \'textdomain\' ),
\'singular_name\' => _x( \'Events Category\', \'textdomain\' ),
\'menu_name\' => __( \'Events Categories\', \'textdomain\' ),
\'all_items\' => __( \'All Items\', \'textdomain\' ),
\'parent_item\' => __( \'Parent Item\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent Item:\', \'textdomain\' ),
\'new_item_name\' => __( \'New Item Name\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New Item\', \'textdomain\' ),
\'edit_item\' => __( \'Edit Item\', \'textdomain\' ),
\'update_item\' => __( \'Update Item\', \'textdomain\' ),
\'view_item\' => __( \'View Item\', \'textdomain\' ),
\'separate_items_with_commas\' => __( \'Separate items with commas\', \'textdomain\' ),
\'add_or_remove_items\' => __( \'Add or remove items\', \'textdomain\' ),
\'choose_from_most_used\' => __( \'Choose from the most used\', \'textdomain\' ),
\'popular_items\' => __( \'Popular Items\', \'textdomain\' ),
\'search_items\' => __( \'Search Items\', \'textdomain\' ),
\'not_found\' => __( \'Not Found\', \'textdomain\' ),
\'no_terms\' => __( \'No items\', \'textdomain\' ),
\'items_list\' => __( \'Items list\', \'textdomain\' ),
\'items_list_navigation\' => __( \'Items list navigation\', \'textdomain\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => false,
\'show_in_rest\' => false,
);
register_taxonomy( \'ecat\', array( \'events\' ), $args );