custom-post-type.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 your post categories to your custom post type */
  49. register_taxonomy_for_object_type('category', 'custom_type');
  50. /* this ads your post 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. /*
  56. for more information on taxonomies, go here:
  57. http://codex.wordpress.org/Function_Reference/register_taxonomy
  58. */
  59. // now let's add custom categories (these act like categories)
  60. register_taxonomy( 'custom_cat',
  61. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  62. array('hierarchical' => true, /* if this is true it acts like categories */
  63. 'labels' => array(
  64. 'name' => __( 'Custom Categories' ), /* name of the custom taxonomy */
  65. 'singular_name' => __( 'Custom Category' ), /* single taxonomy name */
  66. 'search_items' => __( 'Search Custom Categories' ), /* search title for taxomony */
  67. 'all_items' => __( 'All Custom Categories' ), /* all title for taxonomies */
  68. 'parent_item' => __( 'Parent Custom Category' ), /* parent title for taxonomy */
  69. 'parent_item_colon' => __( 'Parent Custom Category:' ), /* parent taxonomy title */
  70. 'edit_item' => __( 'Edit Custom Category' ), /* edit custom taxonomy title */
  71. 'update_item' => __( 'Update Custom Category' ), /* update title for taxonomy */
  72. 'add_new_item' => __( 'Add New Custom Category' ), /* add new title for taxonomy */
  73. 'new_item_name' => __( 'New Custom Category Name' ) /* name title for taxonomy */
  74. ),
  75. 'show_ui' => true,
  76. 'query_var' => true,
  77. )
  78. );
  79. // now let's add custom tags (these act like categories)
  80. register_taxonomy( 'custom_tag',
  81. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  82. array('hierarchical' => false, /* if this is false, it acts like tags */
  83. 'labels' => array(
  84. 'name' => __( 'Custom Tags' ), /* name of the custom taxonomy */
  85. 'singular_name' => __( 'Custom Tag' ), /* single taxonomy name */
  86. 'search_items' => __( 'Search Custom Tags' ), /* search title for taxomony */
  87. 'all_items' => __( 'All Custom Tags' ), /* all title for taxonomies */
  88. 'parent_item' => __( 'Parent Custom Tag' ), /* parent title for taxonomy */
  89. 'parent_item_colon' => __( 'Parent Custom Tag:' ), /* parent taxonomy title */
  90. 'edit_item' => __( 'Edit Custom Tag' ), /* edit custom taxonomy title */
  91. 'update_item' => __( 'Update Custom Tag' ), /* update title for taxonomy */
  92. 'add_new_item' => __( 'Add New Custom Tag' ), /* add new title for taxonomy */
  93. 'new_item_name' => __( 'New Custom Tag Name' ) /* name title for taxonomy */
  94. ),
  95. 'show_ui' => true,
  96. 'query_var' => true,
  97. )
  98. );
  99. ?>