场景
wordpress默认只有一种文章类型,有时候需要添加自定义的文章类型:比如演员、电影、公告等
相关钩子
- register_post_type
代码演示
1、添加以下代码到主体模板文件夹目录function.php中 /** * @return void 公告 */ function my_custom_post_announcement() { $labels = array( 'name' => _x('公告', '公告'), 'singular_name' => _x('announcement', 'announcement'), 'add_new' => _x('add', 'add'), 'add_new_item' => __('add'), 'edit_item' => __('edit'), 'new_item' => __('add'), 'all_items' => __('All items'), 'view_item' => __('View'), 'search_items' => __('Search'), 'not_found' => __('not Found'), 'not_found_in_trash' => __('not found in trash'), 'parent_item_colon' => '', 'menu_name' => '公告' ); $args = array( 'labels' => $labels, 'description' => '', 'public' => true, 'menu_position' => 5, 'supports' => array('title', 'editor', 'thumbnail'), 'has_archive' => true ); register_post_type('announcement', $args); }