要扩展@Jai示例。。。
我的设置
$postType = \'foo\';
$categoryType = \'bar\';
自定义帖子类型
$args = array(
\'labels\' => array(\'name\'=>$postType, ...),
\'rewrite\' => array(\'slug\' => \'all-\'.$postType),
\'taxonomies\' => array($categoryType)
);
register_post_type( \'foo\', $args );
自定义类别分类法
$args = array(
\'labels\' => array( \'name\' => _x( $categoryType, \'taxonomy general name\' )),
\'rewrite\' => array( \'slug\' => $categoryType ),
);
register_taxonomy( $categoryType, array( $postType ), $args );
将类别添加为子菜单项
$wp_term = get_categories( \'taxonomy=\'.$categoryType.\'&type=\'.$postType );
if ( $wp_term ) {
foreach ( $wp_term as $term ) {
// add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = \'\' )
add_submenu_page( \'edit.php?post_type=\'.$postType, $term->name, $term->name, \'manage_options\', \'edit.php?post_type=\'.$postType.\'&\'.$categoryType.\'=\'.$term->slug, \'\');
}
}