custom-post-type.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 separate 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', 'bonestheme'), /* This is the Title of the Group */
  21. 'singular_name' => __('Custom Post', 'bonestheme'), /* This is the individual type */
  22. 'all_items' => __('All Custom Posts', 'bonestheme'), /* the all items menu item */
  23. 'add_new' => __('Add New', 'bonestheme'), /* The add new menu item */
  24. 'add_new_item' => __('Add New Custom Type', 'bonestheme'), /* Add New Display Title */
  25. 'edit' => __( 'Edit', 'bonestheme' ), /* Edit Dialog */
  26. 'edit_item' => __('Edit Post Types', 'bonestheme'), /* Edit Display Title */
  27. 'new_item' => __('New Post Type', 'bonestheme'), /* New Display Title */
  28. 'view_item' => __('View Post Type', 'bonestheme'), /* View Display Title */
  29. 'search_items' => __('Search Post Type', 'bonestheme'), /* Search Custom Type Title */
  30. 'not_found' => __('Nothing found in the Database.', 'bonestheme'), /* This displays if there are no entries yet */
  31. 'not_found_in_trash' => __('Nothing found in Trash', 'bonestheme'), /* 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', 'bonestheme' ), /* 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' => array( 'slug' => 'custom_type', 'with_front' => false ), /* you can specify its url slug */
  43. 'has_archive' => 'custom_type', /* you can rename the slug here */
  44. 'capability_type' => 'post',
  45. 'hierarchical' => false,
  46. /* the next one is important, it tells what's enabled in the post editor */
  47. 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
  48. ) /* end of options */
  49. ); /* end of register post type */
  50. /* this ads your post categories to your custom post type */
  51. register_taxonomy_for_object_type('category', 'custom_type');
  52. /* this ads your post tags to your custom post type */
  53. register_taxonomy_for_object_type('post_tag', 'custom_type');
  54. }
  55. // adding the function to the Wordpress init
  56. add_action( 'init', 'custom_post_example');
  57. /*
  58. for more information on taxonomies, go here:
  59. http://codex.wordpress.org/Function_Reference/register_taxonomy
  60. */
  61. // now let's add custom categories (these act like categories)
  62. register_taxonomy( 'custom_cat',
  63. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  64. array('hierarchical' => true, /* if this is true, it acts like categories */
  65. 'labels' => array(
  66. 'name' => __( 'Custom Categories', 'bonestheme' ), /* name of the custom taxonomy */
  67. 'singular_name' => __( 'Custom Category', 'bonestheme' ), /* single taxonomy name */
  68. 'search_items' => __( 'Search Custom Categories', 'bonestheme' ), /* search title for taxomony */
  69. 'all_items' => __( 'All Custom Categories', 'bonestheme' ), /* all title for taxonomies */
  70. 'parent_item' => __( 'Parent Custom Category', 'bonestheme' ), /* parent title for taxonomy */
  71. 'parent_item_colon' => __( 'Parent Custom Category:', 'bonestheme' ), /* parent taxonomy title */
  72. 'edit_item' => __( 'Edit Custom Category', 'bonestheme' ), /* edit custom taxonomy title */
  73. 'update_item' => __( 'Update Custom Category', 'bonestheme' ), /* update title for taxonomy */
  74. 'add_new_item' => __( 'Add New Custom Category', 'bonestheme' ), /* add new title for taxonomy */
  75. 'new_item_name' => __( 'New Custom Category Name', 'bonestheme' ) /* name title for taxonomy */
  76. ),
  77. 'show_ui' => true,
  78. 'query_var' => true,
  79. )
  80. );
  81. // now let's add custom tags (these act like categories)
  82. register_taxonomy( 'custom_tag',
  83. array('custom_type'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
  84. array('hierarchical' => false, /* if this is false, it acts like tags */
  85. 'labels' => array(
  86. 'name' => __( 'Custom Tags', 'bonestheme' ), /* name of the custom taxonomy */
  87. 'singular_name' => __( 'Custom Tag', 'bonestheme' ), /* single taxonomy name */
  88. 'search_items' => __( 'Search Custom Tags', 'bonestheme' ), /* search title for taxomony */
  89. 'all_items' => __( 'All Custom Tags', 'bonestheme' ), /* all title for taxonomies */
  90. 'parent_item' => __( 'Parent Custom Tag', 'bonestheme' ), /* parent title for taxonomy */
  91. 'parent_item_colon' => __( 'Parent Custom Tag:', 'bonestheme' ), /* parent taxonomy title */
  92. 'edit_item' => __( 'Edit Custom Tag', 'bonestheme' ), /* edit custom taxonomy title */
  93. 'update_item' => __( 'Update Custom Tag', 'bonestheme' ), /* update title for taxonomy */
  94. 'add_new_item' => __( 'Add New Custom Tag', 'bonestheme' ), /* add new title for taxonomy */
  95. 'new_item_name' => __( 'New Custom Tag Name', 'bonestheme' ) /* name title for taxonomy */
  96. ),
  97. 'show_ui' => true,
  98. 'query_var' => true,
  99. )
  100. );
  101. /*
  102. looking for custom meta boxes?
  103. check out this fantastic tool:
  104. https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
  105. */
  106. ?>