/**
* an example of registering a post type called "document" including providing contextual help
*/
add_action('init', 'codex_custom_init');
function codex_custom_init() {
$labels = array (
'name' => _x('文档',
'post type general name'
), 'singular_name' => _x('文档', 'post type singular name'), 'add_new' => _x('添加', 'document'), 'add_new_item' => __('添加文档'), 'edit_item' => __('编辑文档'), 'new_item' => __('新建'), 'all_items' => __('所有文档'), 'view_item' => __('查看文档'), 'search_items' => __('搜索文档'), 'not_found' => __('没有找到文档'), 'not_found_in_trash' => __('回收站中没有找到文档'), 'parent_item_colon' => '', 'menu_name' => '文档');
$args = array (
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array (
'title',
'editor',
'author',
'thumbnail',
'excerpt',
'comments'
),
'taxonomies' => array (
'category',
'post_tag'
) // this is IMPORTANT
);
register_post_type('document', $args);
}
将上面的代码添加到functions.php中,然后在后台就会看到我们新注册的文档类型。
上面的代码调用了一个register_post_type('document', $args);函数,它会注册一种新的post类型。