WordPress自定义帖子类型

时间:2013-10-07 01:09:55

标签: wordpress

我目前正在尝试使用WOrdPress自定义帖子类型来创建支持票证系统,目前我拥有以下内容并且工作正常。

add_action( 'init', 'create_support_tickets' );


function create_support_tickets() {
register_post_type( 'support_ticket',
array(
'labels' => array(
'name' => 'Tickets',
'singular_name' => 'Ticket',
'add_new' => 'Add New',
'add_new_item' => 'Add New Ticket',
'edit' => 'Edit',
'edit_item' => 'Edit Ticket',
'new_item' => 'New Ticket',
'view' => 'View',
'view_item' => 'View Ticket',
'search_items' => 'Search Tickets',
'not_found' => 'No Tickets found',
'not_found_in_trash' =>
'No Tickets found in Trash',
'parent' => 'Parent Ticket'
),
'public' => true,
'menu_position' => 15,
'supports' =>
array( 'title', 'editor', 'comments',
'thumbnail',  ),
'taxonomies' => array( '' ),
'menu_icon' =>
plugins_url( 'images/image.png', __FILE__ ),
'has_archive' => true
)
);

上面的代码有效,但我不知道如何为上面的门票添加类别,我希望能够将这些门票分配给具有员工角色的WordPress用户的其他员工。

5 个答案:

答案 0 :(得分:2)

这是一个关于 WordPress自定义帖子类型的精彩教程,每个点都有完整的描述,可以在将来为您提供很多帮助。

WordPress Custom Post Type

另一个例子是http://blog.teamtreehouse.com/create-your-first-wordpress-custom-post-type,但我个人建议你按照第一个例子。

干杯;)

答案 1 :(得分:1)

在function.php中添加此代码:

add_action( 'init', 'create_services' );

function create_services() {
  $labels = array(
    'name' => _x('SERVICES', 'post type general name'),
    'singular_name' => _x('SERVICES', 'post type singular name'),
    'add_new' => _x('Add New', 'SERVICES'),
    'add_new_item' => __('Add New SERVICES'),
    'edit_item' => __('Edit SERVICES'),
    'new_item' => __('New SERVICES'),
    'view_item' => __('View SERVICES'),
    'search_items' => __('Search SERVICES'),
    'not_found' =>  __('No SERVICES found'),
    'not_found_in_trash' => __('No SERVICES found in Trash'),
    'parent_item_colon' => ''
  );

  $supports = array('title','editor','excerpt', 'trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes');

  register_post_type( 'services', 
    array(
      'labels' => $labels,
      'public' => true,
      'supports' => $supports,
      'hierarchical' => true,
      'rewrite' => array('slug' => 'services', 'with_front' => false),
    )
  );
}

答案 2 :(得分:0)

传递'taxonomies' => array('category'),。如果你使用自定义帖子类型,你真的需要了解分类法,以便在wp中真正使用自定义帖子类型

答案 3 :(得分:0)

答案 4 :(得分:-1)

      /**  Meet the team custom post 
You can use below wordpress script to create custom post type without any plugins */

      $labels = array(
        'name' => _x('Team', 'Team', 'Team') ,
        'singular_name' => _x('Team', 'Team', 'rjis') ,
        'menu_name' => _x('Meet the Team', 'admin menu', 'rjis') ,
        'name_admin_bar' => _x('Team', 'add new on admin bar', 'rjis') ,
        'add_new' => _x('Add New', 'Team', 'rjis') ,
        'add_new_item' => __('Add New Team', 'rjis') ,
        'new_item' => __('New Team', 'rjis') ,
        'edit_item' => __('Edit Team', 'rjis') ,
        'view_item' => __('View Team', 'rjis') ,
        'all_items' => __('All Team Members', 'rjis') ,
        'search_items' => __('Search Team', 'rjis') ,
        'parent_item_colon' => __('Parent Team:', 'rjis') ,
        'not_found' => __('No Team found.', 'rjis') ,
        'not_found_in_trash' => __('No Team found in Trash.', 'rjis')
      );
      $args = array(
        'labels' => $labels,
        'description' => __('Description.', 'Meet the team') ,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array(
          'slug' => 'team'
        ) ,
        'capability_type' => 'post',
        'has_archive' => false,
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array(
          'title',
          'editor',
          'author',
          'thumbnail',
          'excerpt'
        ) ,
        'menu_icon' => PLUGIN_URL . "images/team.png"
      );

     register_post_type('team', $args);