Successfully reported this slideshow.
Your SlideShare is downloading. ×

Custom post-types & taxonomies

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Case  studies
Case studies
Loading in …3
×

Check these out next

1 of 11 Ad

More Related Content

Recently uploaded (20)

Advertisement

Custom post-types & taxonomies

  1. 1. CUSTOM POST TYPES & TAXONOMIES Christopher Reding - @creding - April 18th 2011
  2. 2. What? Posts in Wordpress are stored in the wp_posts table. Within this table there is a column for the post type. Using this column Wordpress can determine the correct form of presentation or relationship the post requires when querying for that post type. Custom Post Types are no different, they too are stored in the wp_posts table and have all the characteristics of their sibling objects. The only real difference is you define them. The name, attributes, and abilities can be customized allowing you to expand the possibilities of Wordpress beyond what many ever thought possible without a plugin.
  3. 3. What? Taxonomies are the categories and tags we all know and love. They enable posts to be divided and subdivided into relational containers making it a breeze to navigate as well as see related topics. Custom taxonomies are no different, they can do all the same things. The only difference is that you are in control of what that taxonomy is applied to and how it can be used - just like custom post types.
  4. 4. Creating Your Custom Post Type Beer $labels = array( 'name' => _x('Beer', 'post type general name'), Define Labels 'singular_name' => _x('Beer', 'post type singular name'), 'add_new' => _x('Add New', 'beer'), 'add_new_item' => __('Add New Beer'), 'edit_item' => __('Edit Beer'), 'new_item' => __('New Beer'), 'view_item' => __('View Beer'), 'search_items' => __('Search For Beers'), 'not_found' => __('No beers found'), 'not_found_in_trash' => __('No beers found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Beers' );
  5. 5. Creating Your Custom Post Type Beer $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, Define Attributes 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 10, 'supports' => array('title','editor','author','thumbnail','excerpt','comments') ); Register It register_post_type('beer',$args);
  6. 6. WHAT ABOUT CUSTOM FIELDS?
  7. 7. Custom Meta Boxes Now that you have a custom post type you may want to define some extra fields. Using a custom meta box you can create a form containing the fields you want to use. You then use that form to populate the post’s meta data. The wp_postmeta table in the database enables us to relate data to the post and give it a key name (meta_key => meta_value) This is made even easier using the WPAlchemy MetaBox PHP class http://www.farinspace.com/wpalchemy-metabox/
  8. 8. EVENT META BOX Adds a form to the event custom post type allowing specific event data to be stored.
  9. 9. AND THE FRONT END Event custom post type displayed from the front end.
  10. 10. Why? Pre-formatted content such as an event. To isolate content into silos making it easier on the content creators. Save the WP database from the ravage of excessive table bloat. A better integration for plugin creators who want to take advantage of built-in WP functions such as search, archives, and permalinks.
  11. 11. QUESTIONS? @creding http://facebook.com/creding http://www.linkedin.com/in/creding http://about.me/creding

Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

×