我有一个名为“News”的自定义帖子类型,如下所示:
/**
* Register "News" custom post type
*/
function news_custom_post_type() {
$labels = array(
\'name\' => _x( \'News\', \'Post Type General Name\', \'school\' ),
\'singular_name\' => _x( \'News Item\', \'Post Type Singular Name\', \'school\' ),
\'menu_name\' => __( \'News\', \'school\' ),
\'name_admin_bar\' => __( \'News\', \'school\' ),
\'archives\' => __( \'News Archives\', \'school\' ),
\'attributes\' => __( \'News Attributes\', \'school\' ),
\'parent_item_colon\' => __( \'Parent Post:\', \'school\' ),
\'all_items\' => __( \'All Posts\', \'school\' ),
\'add_new_item\' => __( \'Add a New Post\', \'school\' ),
\'add_new\' => __( \'Add New\', \'school\' ),
\'new_item\' => __( \'New Post\', \'school\' ),
\'edit_item\' => __( \'Edit Post\', \'school\' ),
\'update_item\' => __( \'Update Post\', \'school\' ),
\'view_item\' => __( \'View Post\', \'school\' ),
\'view_items\' => __( \'View Posts\', \'school\' ),
\'search_items\' => __( \'Search Posts\', \'school\' ),
\'not_found\' => __( \'Not found\', \'school\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'school\' ),
\'featured_image\' => __( \'Featured Image\', \'school\' ),
\'set_featured_image\' => __( \'Set featured image\', \'school\' ),
\'remove_featured_image\' => __( \'Remove featured image\', \'school\' ),
\'use_featured_image\' => __( \'Use as featured image\', \'school\' ),
\'insert_into_item\' => __( \'Insert into post\', \'school\' ),
\'uploaded_to_this_item\' => __( \'Uploaded to this post\', \'school\' ),
\'items_list\' => __( \'Posts list\', \'school\' ),
\'items_list_navigation\' => __( \'Posts list navigation\', \'school\' ),
\'filter_items_list\' => __( \'Filter posts list\', \'school\' ),
);
$args = array(
\'label\' => __( \'News Post\', \'school\' ),
\'description\' => __( \'A custom post type for news posts.\', \'school\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\' ),
\'taxonomies\' => array( \'news\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'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\',
);
register_post_type( \'news\', $args );
}
add_action( \'init\', \'news_custom_post_type\', 0 );
我还为此帖子类型设置了分类:
/**
* Register "News" Categories
*/
function news_categories() {
$labels = array(
\'name\' => _x( \'Categories\', \'Taxonomy General Name\', \'school\' ),
\'singular_name\' => _x( \'Category\', \'Taxonomy Singular Name\', \'school\' ),
\'menu_name\' => __( \'Categories\', \'school\' ),
\'all_items\' => __( \'All Items\', \'school\' ),
\'parent_item\' => __( \'Parent Category\', \'school\' ),
\'parent_item_colon\' => __( \'Parent Category:\', \'school\' ),
\'new_item_name\' => __( \'New Category Name\', \'school\' ),
\'add_new_item\' => __( \'Add New Category\', \'school\' ),
\'edit_item\' => __( \'Edit Category\', \'school\' ),
\'update_item\' => __( \'Update Category\', \'school\' ),
\'view_item\' => __( \'View Category\', \'school\' ),
\'separate_items_with_commas\' => __( \'Separate categories with commas\', \'school\' ),
\'add_or_remove_items\' => __( \'Add or remove categories\', \'school\' ),
\'choose_from_most_used\' => __( \'Choose from the most used\', \'school\' ),
\'popular_items\' => __( \'Popular Categories\', \'school\' ),
\'search_items\' => __( \'Search Categories\', \'school\' ),
\'not_found\' => __( \'Not Found\', \'school\' ),
\'no_terms\' => __( \'No items\', \'school\' ),
\'items_list\' => __( \'Categories list\', \'school\' ),
\'items_list_navigation\' => __( \'Categories list navigation\', \'school\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
);
register_taxonomy( \'news\', array( \'news\' ), $args );
}
add_action( \'init\', \'news_categories\', 0 );
我已经通过WP Admin添加了我的类别,并创建了三篇带有这些类别的帖子。
通过小部件,我添加了“类别”小部件。当您访问新闻存档页面时,小部件会显示“无类别”。
有什么想法吗?