1、注册自定义文章类型
function lined_create_document() {
$labels = array(
'name' => __( 'Document', 'lined' ),
'singular_name' => __( 'Document', 'lined' ),
'menu_name' => __( 'Document', 'lined' ), 'admin menu',
'name_admin_bar' => __( 'Document', 'lined' ),
'add_new' => __( 'Add New', 'lined' ),
'add_new_item' => __( 'Add New Document', 'lined' ),
'new_item' => __( 'New Document', 'lined' ),
'edit' => __( 'Edit', 'lined' ),
'edit_item' => __( 'Edit Document', 'lined' ),
'view' => __( 'View', 'lined' ),
'view_item' => __( 'View Document', 'lined' ),
'all_items' => __( 'All Document', 'lined' ),
'search_items' => __( 'Search Document', 'lined' ),
'parent' => __( 'Parent', 'lined' ),
'parent_item_colon' => __( 'Parent Document', 'lined' ),
'not_found' => __( 'You have not publish any document.', 'lined' ),
'not_found_in_trash' => __( 'has no document in trash.', 'lined' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'rewrite' => array('slug' => 'doc'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'taxonomies' => 'doc_type'
);
register_post_type( 'doc', $args );
}
add_action( 'init', 'lined_create_document' );
2、添加自定义分类
function lined_create_doc_taxonomies() {
$labels = array(
'name' => __( 'Contents', 'puji' ),
'singular_name' => __( 'Contents', 'puji' ),
'search_items' => __( 'Search Contents', 'puji' ),
'all_items' => __( 'All Contents', 'puji' ),
'parent_item' => __( 'Parent genre', 'puji' ),
'parent_item_colon' => __( 'Parent Genre:', 'puji' ),
'edit_item' => __( 'Edit Contents', 'puji' ),
'update_item' => __( 'Update Contents', 'puji' ),
'add_new_item' => __( 'Add Contents', 'puji' ),
'new_item_name' => __( 'New Genre Name', 'puji' ),
'menu_name' => __( 'Contents', 'puji' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'contents' ),
'show_in_rest' => true
);
register_taxonomy( 'contents', 'doc', $args );
}
add_action( 'init', 'lined_create_doc_taxonomies', 0 );