Wordpress注册自定义post类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress注册自定义post类型相关的知识,希望对你有一定的参考价值。

  1. // creating (registering) the custom type
  2. $labels = array(
  3. 'name' => _x('Custom Types', 'post type general name', 'big_bang'), //This is the title of the group
  4. 'singular_name' => _x('Custom Post', 'post type singular name', 'big_bang'), //This is the individual type
  5. 'add_new' => _x('Add New', 'custom post type item', 'big_bang'), //The add new menu item
  6. 'add_new_item' => __('Add New Custom Type', 'big_bang'), // Add new Display Title
  7. 'all_items' => __('All Custom Types', 'big_bang'), // The All Items in the Menu
  8. 'edit' => __('Edit', 'big_bang'), //Edit Dialog
  9. 'edit_item' => __('Edit Custom Type', 'big_bang'), //Edit Display Title
  10. 'new_item' => __('New Custom Type', 'big_bang'), //New Display Title
  11. 'view_item' => __('View Custom Type', 'big_bang'), //View Display Title
  12. 'search_items' => __('Search Custom Post Type', 'big_bang'), //Search Custom Type Title
  13. 'not_found' => __('Nothing found in the Database.', 'big_bang'), //This displays if there are no entries yet
  14. 'not_found_in_trash'=> __('Nothing found in Trash', 'big_bang'), //This displays if there is nothing in the trash
  15. 'parent_item_colon' => ''
  16. );
  17. $args = array(
  18. 'labels' => $labels,
  19. 'description' => __('This is an example custom post type.', 'big_bang'), //Custom Type Description
  20. 'public' => true,
  21. 'publicly_queryable' => true,
  22. 'exclude_from_search' => false,
  23. 'show_ui' => true,
  24. 'query_var' => true,
  25. 'menu_position' => 8, //This is what order you want it to appear in on the left hand side menu
  26. 'menu_icon' => get_stylesheet_directory_uri() . '/images/custom-post-icon.png', //the icon for the custom post type menu
  27. 'rewrite' => true,
  28. 'capability_type' => 'post',
  29. 'hierachical' => false,
  30. // the next one is important, it tells what's enabled in the post editor
  31. 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
  32. );
  33.  
  34. register_post_type( 'custom_type', $args); // (http://codex.wordpress.org/Function_Reference/register_post_type)

以上是关于Wordpress注册自定义post类型的主要内容,如果未能解决你的问题,请参考以下文章

WordPress注册自定义post类型代码

Wordpress注册自定义post类型

从 Wordpress 取消注册自定义帖子类型

Wordpress 自定义帖子类型类别

用于自定义帖子类型的 Wordpress 多个 slug

没有自定义帖子类型 slug 的 WordPress slug