您可以将此行添加到注册自定义帖子类型的代码中:
\'taxonomies\' => array( \'category\' ),
或者,您可以添加分类法而不是类别:
add_action( \'init\', \'cpt_type_taxonomy\' );
function cpt_type_taxonomy() {
register_taxonomy( \'portfolio-type\', \'portfolio\',
array(
\'labels\' => array(
\'name\' => _x( \'Types\', \'taxonomy general name\', \'theme\' ),
\'add_new_item\' => __( \'Add New Portfolio Type\', \'theme\' ),
\'new_item_name\' => __( \'New Portfolio Type\', \'theme\' ),
),
\'exclude_from_search\' => true,
\'has_archive\' => true,
\'hierarchical\' => true,
\'rewrite\' => array( \'slug\' => \'portfolio-type\', \'with_front\' => false ),
\'show_ui\' => true,
\'show_tagcloud\' => false,
)
);
}
然后将这一行添加到注册自定义帖子类型的代码中。
\'taxonomies\' => array( \'portfolio-type\' ),
以下是注册自定义帖子类型的所有代码:
add_action( \'init\', \'register_custom_post_type\' );
function register_custom_post_type() {
register_post_type( \'portfolio\',
array(
\'labels\' => array(
\'name\' => __( \'Portfolio\', \'theme\' ),
\'singular_name\' => __( \'Portfolio\', \'theme\' ),
),
\'has_archive\' => true,
\'hierarchical\' => true,
\'menu_icon\' => \'dashicons-icon-name\',
\'public\' => true,
\'rewrite\' => array( \'slug\' => \'portfolio\', \'with_front\' => false ),
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'trackbacks\', \'custom-fields\', \'revisions\', \'page-attributes\' ),
\'taxonomies\' => array( \'portfolio-type\' ),
)
);
}