你要找的是所谓的自定义帖子类型,或者短期内称为CPT。要注册一个新的帖子类型,可以使用这样一个简单的代码,它将添加一个名为article
至您的管理面板:
function register_my_post_type() {
$labels = array(
\'name\' => __( \'Articles\', \'text-domain\' ),
\'singular_name\' => __( \'Article\', \'text-domain\' ),
\'menu_name\' => __( \'Articles\', \'text-domain\' ),
\'parent_item_colon\' => __( \'Parent Article\', \'text-domain\' ),
\'all_items\' => __( \'All Articles\', \'text-domain\' ),
\'view_item\' => __( \'View Article\', \'text-domain\' ),
\'add_new_item\' => __( \'Add New Article\', \'text-domain\' ),
\'add_new\' => __( \'Add New\', \'text-domain\' ),
\'edit_item\' => __( \'Edit Article\', \'text-domain\' ),
\'update_item\' => __( \'Update Article\', \'text-domain\' ),
\'search_items\' => __( \'Search Artcile\', \'text-domain\' ),
\'not_found\' => __( \'Not Found\', \'text-domain\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'text-domain\' ),
);
$args = array(
\'label\' => __( \'articles\', \'text-domain\' ),
\'description\' => __( \'Website\\\'s articles\', \'text-domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'revisions\', \'custom-fields\', ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'post\',
\'taxonomies\' => array( \'category\',\'post_tag\' ),
);
register_post_type( \'article\', $args );
}
add_action( \'init\', \'register_my_post_type\', 0 );
第一个数组包括帖子类型各个部分的名称和标题,例如单数/复数标题、菜单名称等。
第二个数组包含诸如被包括在搜索中、公开等特性。
有关这方面的更多详细信息,请查看官方codex 第页关于register_post_type
.