custom-post-type.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /* Bones Custom Post Type Example
  3. This page walks you through creating
  4. a custom post type and taxonomies. You
  5. can edit this one or copy the following code
  6. to create another one.
  7. I put this in a seperate file so as to
  8. keep it organized. I find it easier to edit
  9. and change things if they are concentrated
  10. in their own file.
  11. Developed by: Eddie Machado
  12. URL: http://themble.com/bones/
  13. */
  14. // let's create the function for the custom type
  15. function custom_post_example() {
  16. // creating (registering) the custom type
  17. register_post_type( 'custom_type', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
  18. // let's now add all the options for this post type
  19. array('labels' => array(
  20. 'name' => __('Custom Types', 'post type general name'), /* This is the Title of the Group */
  21. 'singular_name' => __('Custom Post', 'post type singular name'), /* This is the individual type */
  22. 'all_items' => __('All Custom Posts'), /* the all items menu item */
  23. 'add_new' => __('Add New', 'custom post type item'), /* The add new menu item */
  24. 'add_new_item' => __('Add New Custom Type'), /* Add New Display Title */
  25. 'edit' => __( 'Edit' ), /* Edit Dialog */
  26. 'edit_item' => __('Edit Post Types'), /* Edit Display Title */
  27. 'new_item' => __('New Post Type'), /* New Display Title */
  28. 'view_item' => __('View Post Type'), /* View Display Title */
  29. 'search_items' => __('Search Post Type'), /* Search Custom Type Title */
  30. 'not_found' => __('Nothing found in the Database.'), /* This displays if there are no entries yet */
  31. 'not_found_in_trash' => __('Nothing found in Trash'), /* This displays if there is nothing in the trash */
  32. 'parent_item_colon' => ''
  33. ), /* end of arrays */
  34. 'description' => __( 'This is the example custom post type' ), /* Custom Type Description */
  35. 'public' => true,
  36. 'publicly_queryable' => true,
  37. 'exclude_from_search' => false,
  38. 'show_ui' => true,
  39. 'query_var' => true,
  40. 'menu_position' => 8, /* this is what order you want it to appear in on the left hand side menu */
  41. 'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
  42. 'rewrite' => true,
  43. 'capability_type' => 'post',
  44. 'hierarchical' => false,
  45. /* the next one is important, it tells what's enabled in the post editor */
  46. 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
  47. ) /* end of options */
  48. ); /* end of register post type */
  49. /* this ads your post categories to your custom post type */
  50. register_taxonomy_for_object_type('category', 'custom_type');
  51. /* this ads your post tags to your custom post type */
  52. register_taxonomy_for_object_type('post_tag', 'custom_type');
  53. }
  54. // adding the function to the Wordpress init
  55. add_action( 'init', 'custom_post_example');
  56. /*
  57. for more information on taxonomies, go here:
  58. http://codex.wordpress.org/Function_Reference/register_taxonomy
  59. */
  60. // now let's add custom categories (these act like categories)
  61. register_taxonomy( 'custom_cat',
  62. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  63. array('hierarchical' => true, /* if this is true it acts like categories */
  64. 'labels' => array(
  65. 'name' => __( 'Custom Categories' ), /* name of the custom taxonomy */
  66. 'singular_name' => __( 'Custom Category' ), /* single taxonomy name */
  67. 'search_items' => __( 'Search Custom Categories' ), /* search title for taxomony */
  68. 'all_items' => __( 'All Custom Categories' ), /* all title for taxonomies */
  69. 'parent_item' => __( 'Parent Custom Category' ), /* parent title for taxonomy */
  70. 'parent_item_colon' => __( 'Parent Custom Category:' ), /* parent taxonomy title */
  71. 'edit_item' => __( 'Edit Custom Category' ), /* edit custom taxonomy title */
  72. 'update_item' => __( 'Update Custom Category' ), /* update title for taxonomy */
  73. 'add_new_item' => __( 'Add New Custom Category' ), /* add new title for taxonomy */
  74. 'new_item_name' => __( 'New Custom Category Name' ) /* name title for taxonomy */
  75. ),
  76. 'show_ui' => true,
  77. 'query_var' => true,
  78. )
  79. );
  80. // now let's add custom tags (these act like categories)
  81. register_taxonomy( 'custom_tag',
  82. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  83. array('hierarchical' => false, /* if this is false, it acts like tags */
  84. 'labels' => array(
  85. 'name' => __( 'Custom Tags' ), /* name of the custom taxonomy */
  86. 'singular_name' => __( 'Custom Tag' ), /* single taxonomy name */
  87. 'search_items' => __( 'Search Custom Tags' ), /* search title for taxomony */
  88. 'all_items' => __( 'All Custom Tags' ), /* all title for taxonomies */
  89. 'parent_item' => __( 'Parent Custom Tag' ), /* parent title for taxonomy */
  90. 'parent_item_colon' => __( 'Parent Custom Tag:' ), /* parent taxonomy title */
  91. 'edit_item' => __( 'Edit Custom Tag' ), /* edit custom taxonomy title */
  92. 'update_item' => __( 'Update Custom Tag' ), /* update title for taxonomy */
  93. 'add_new_item' => __( 'Add New Custom Tag' ), /* add new title for taxonomy */
  94. 'new_item_name' => __( 'New Custom Tag Name' ) /* name title for taxonomy */
  95. ),
  96. 'show_ui' => true,
  97. 'query_var' => true,
  98. )
  99. );
  100. ?>