起点,将默认类别添加到附件帖子类型:
add_action( \'init\', \'wpse_77550_media_categories\' );
function wpse_77550_media_categories()
{
register_taxonomy_for_object_type( \'category\', \'attachment\' );
}
或者向附件帖子类型添加自定义分类法(不确定为什么分类法不会显示在媒体菜单中-
show_ui=>true
-, 尽管编辑附件时会显示元框):
add_action( \'admin_init\', \'wpse_77550_media_taxonomy\' );
function wpse_77550_media_taxonomy()
{
$labels = array(
\'name\' => _x( \'Genres\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Genre\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Genres\' ),
\'all_items\' => __( \'All Genres\' ),
\'parent_item\' => __( \'Parent Genre\' ),
\'parent_item_colon\' => __( \'Parent Genre:\' ),
\'edit_item\' => __( \'Edit Genre\' ),
\'update_item\' => __( \'Update Genre\' ),
\'add_new_item\' => __( \'Add New Genre\' ),
\'new_item_name\' => __( \'New Genre Name\' ),
\'menu_name\' => __( \'Genre\' ),
);
register_taxonomy(\'genre\',\'attachment\', array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'genre\' ),
));
}
参考资料:
How To: Add Taxonomies to Your Custom Post Types in WordPress