跟随this 创建自定义帖子类型的教程。
以下是符合您要求的工作代码:
function create_post_type_event() {
//Create custom post type for event
$labels = array(
\'name\' => _x(\'Event\', \'post type general name\'),
\'singular_name\' => _x(\'Event\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'event\'),
\'add_new_item\' => __(\'Add New Event\'),
\'edit_item\' => __(\'Edit Event\'),
\'new_item\' => __(\'New Event\'),
\'all_items\' => __(\'All Events\'),
\'view_item\' => __(\'View Event\'),
\'search_items\' => __(\'Search Event\'),
\'not_found\' => __(\'No event found\'),
\'not_found_in_trash\' => __(\'No event found in Trash\'),
\'parent_item_colon\' => \'\',
\'menu_name\' => __(\'Event\')
);
$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\' => 5,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\', \'custom-fields\' )
);
register_post_type(\'event\',$args);
flush_rewrite_rules(); // Flush the rewrite rules and re-create the above for custom post types
}
add_action( \'init\', \'create_post_type_event\' );
创建此之后
cpt
您可以创建
single-event.php
文件,它应该可以正常工作。