custom-post-type.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 'add_new' => __('Add New', 'custom post type item'), /* The add new menu item */
  23. 'add_new_item' => __('Add New Custom Type'), /* Add New Display Title */
  24. 'edit' => __( 'Edit' ), /* Edit Dialog */
  25. 'edit_item' => __('Edit Post Types'), /* Edit Display Title */
  26. 'new_item' => __('New Post Type'), /* New Display Title */
  27. 'view_item' => __('View Post Type'), /* View Display Title */
  28. 'search_items' => __('Search Post Type'), /* Search Custom Type Title */
  29. 'not_found' => __('Nothing found in the Database.'), /* This displays if there are no entries yet */
  30. 'not_found_in_trash' => __('Nothing found in Trash'), /* This displays if there is nothing in the trash */
  31. 'parent_item_colon' => ''
  32. ), /* end of arrays */
  33. 'description' => __( 'This is the example custom post type' ), /* Custom Type Description */
  34. 'public' => true,
  35. 'publicly_queryable' => true,
  36. 'exclude_from_search' => false,
  37. 'show_ui' => true,
  38. 'query_var' => true,
  39. 'menu_position' => 8, /* this is what order you want it to appear in on the left hand side menu */
  40. 'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
  41. 'rewrite' => true,
  42. 'capability_type' => 'post',
  43. 'hierarchical' => false,
  44. /* the next one is important, it tells what's enabled in the post editor */
  45. 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
  46. ) /* end of options */
  47. ); /* end of register post type */
  48. /* this ads regular categories to your custom post type */
  49. register_taxonomy_for_object_type('category', 'custom_type');
  50. /* this ads regular tags to your custom post type */
  51. register_taxonomy_for_object_type('post_tag', 'custom_type');
  52. }
  53. // adding the function to the Wordpress init
  54. add_action( 'init', 'custom_post_example');
  55. // now let's add custom categories (http://codex.wordpress.org/Function_Reference/register_taxonomy)
  56. register_taxonomy( 'custom_cat',
  57. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  58. array('hierarchical' => true,
  59. 'labels' => array(
  60. 'name' => __( 'Custom Categories' ), /* name of the custom taxonomy */
  61. 'singular_name' => __( 'Custom Category' ), /* single taxonomy name */
  62. 'search_items' => __( 'Search Custom Categories' ), /* search title for taxomony */
  63. 'all_items' => __( 'All Custom Categories' ), /* all title for taxonomies */
  64. 'parent_item' => __( 'Parent Custom Category' ), /* parent title for taxonomy */
  65. 'parent_item_colon' => __( 'Parent Custom Category:' ), /* parent taxonomy title */
  66. 'edit_item' => __( 'Edit Custom Category' ), /* edit custom taxonomy title */
  67. 'update_item' => __( 'Update Custom Category' ), /* update title for taxonomy */
  68. 'add_new_item' => __( 'Add New Custom Category' ), /* add new title for taxonomy */
  69. 'new_item_name' => __( 'New Custom Category Name' ) /* name title for taxonomy */
  70. ),
  71. 'show_ui' => true,
  72. 'query_var' => true,
  73. )
  74. );
  75. ?>