Custom Post Types and Taxonomies


Published on

WordPress just got CMSier

Published in: Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Custom Post Types and Taxonomies

  1. 1. Custom Post Types & Taxonomies<br />WordPress just got CMSier<br />
  2. 2. Who Am I?<br />I am a self-taught, freelance designer who has leveraged trial, error, and observation to become a WordPress expert. <br />While I specialize in WordPress themes and CMS development, I also do all levels of Web Design and XHTML/CSS coding.<br />I freelance some through my personal brand, Tammy Hart Designs, and I also work a full time gig at Infomediahere in Birmingham.<br /> @tammyhart<br />
  3. 3. What is a Post Type?<br />Posts, pages and more! Oh my!<br />
  4. 4. How Does it Work?<br />Content goes into the posts table<br />Each content item is assigned a post_type<br />Custom types are now easier to create and manage<br />
  5. 5. Built in Types<br />Main Content<br />Post<br />Page<br />Other<br />Attachment<br />Revision<br />Nav Menu Item<br />
  6. 6. What Is a taxonomy?<br />Read my lips, now new taxonomies<br />
  7. 7. How Do They Work?<br />Terms and their unique ID’s are saved in the terms table<br />Terms are assigned a taxonomy in the term_taxonomy table<br />Terms are related to posts (of all types) in the term_relationships table<br />
  8. 8. Built in Taxonomies<br />Post Taxonomies<br />Category<br />Post Tag<br />Other<br />Link Category<br />Nav Menu<br />
  9. 9. Hand Coding<br />The hard way<br />
  10. 10. Register a Post Type<br />function post_type_movies(){<br /> register_post_type('movies',<br /> array('label'=> __('Movies'), <br /> 'public'=>true, <br /> 'show_ui'=>true,<br />'supports' =>array(<br />'post-thumbnails',<br />'excerpts',<br /> 'trackbacks',<br /> 'custom-fields',<br /> 'comments',<br /> 'revisions')<br />)<br />);<br /> register_taxonomy_for_object_type('post_tag', 'movies');<br />}<br />add_action('init', 'post_type_movies');<br />First Impressions of Custom Post Type by Frank Bültge on<br /><br />
  11. 11. Default Arguments<br />// Args prefixed with an underscore are reserved for internal use.<br />$defaults =array(<br />'label' =>false,<br />'publicly_queryable' => null,<br />'exclude_from_search' => null,<br />'_builtin' =>false,<br />'_edit_link' =>'post.php?post=%d',<br />'capability_type'=>'post',<br />'hierarchical' => false,<br />'public' => false,<br />'rewrite' =>true,<br />'query_var' =>true,<br />'supports' =>array(),<br />'register_meta_box_cb' => null,<br />'taxonomies' =>array(),<br />'show_ui' => null<br />);<br />First Impressions of Custom Post Type by Frank Bültge on<br /><br />
  12. 12. The Taxonomy Code<br />function post_type_movies(){<br />…<br />register_taxonomy('actor', 'movies', <br />array(<br />'hierarchical'=>true, <br />'label'=> __('Actor')<br />) <br />); <br />register_taxonomy(‘director', 'movies',<br />array(<br /> 'hierarchical'=>false,<br />'label'=>__(‘Director'),<br />'query_var'=>‘director',<br />'rewrite' =>array('slug'=>‘director')<br /> )<br /> );<br />}<br />add_action('init', 'post_type_movies');<br />First Impressions of Custom Post Type by Frank Bültge on<br /><br />
  13. 13. Using Plugins<br />The easy way<br />
  14. 14. “<br />Overheard<br />WordCamp Birmingham 2009<br />WordPress is the iPhone of the internet. You’ll always hear, “There’s a plugin for that!”<br />
  15. 15. Plugins for Creating Them<br />Custom Post Type UI<br />Creates both<br />TONS of labeling options<br />WP Post Type UI<br />Creates both<br />Buggy<br />Allows a custom icon<br />More Types & More Taxonomies<br />Allows you to override built in types and taxonomies<br />Allows a custom icon<br />Works seamlessly with the More Fields plugin (stay tuned for more)<br />
  16. 16. Plugins for Manipulating Them<br />Custom Post Type Order<br />Drag and drop ordering<br />Simple Custom Post Type Archives<br />Adds support for custom post type archive permalinks<br />Adds new body classes to custom post type archives<br />Adds a new conditional, is_custom_post_type_archive<br />Fixes the wp_title output on custom post type archives to show the custom type's label<br />Adds custom post type feeds<br />And more…<br />Post Type Switcher<br />Change the post type one item at a time<br />Convert Post Types<br />Bulk edit post types<br />
  17. 17. Custom Templates<br />Now what do I do?<br />
  18. 18. Template Hierarchy<br />Custom Post Type<br />single-{post_type}.php<br />single.php<br />index.php<br />Custom Taxonomy<br />taxonomy-{taxonomy}-{term}.php<br />taxonomy-{taxonomy}.php<br />taxonomy.php<br />archive.php<br />index.php<br />
  19. 19. Custom Loops & Queries<br />This gets hardcore<br />
  20. 20. The Loop<br />The Basic Loop<br /><?<br />$loop =newWP_query('post_type=movies');<br />while ($loop->have_posts()): $loop->the_post();<br />?><br />... Do Stuff Here ...<br /><?endwhile; ?><br />Add Custom Taxonomies<br />$loop =newWP_query('post_type=movies&actor=joaquin-phoenix');<br />$loop =newWP_query('post_type=movies&actor=joaquin-phoenix&director=m-night-shyamalan');<br />
  21. 21. Term Lists<br />Get All Terms<br />$terms =get_terms('actors', 'order_by=count&order=DESC');<br />Get Terms in a Post<br />get_the_term_list( $post->ID, 'actors', '<p>Actors: ', ',', '</p>' )<br />Other Functions<br />get_term<br />get_term_children<br />get_term_by<br />get_taxonomies<br />
  22. 22. More Custom Content<br />But wait, there’s more!<br />
  23. 23. “<br />Matt Mullenweg<br />WordCamp Birmingham 2009<br />I like what you’re doing; I just don’t like the way you’re having to do it. So I’m going to make it better.<br />
  24. 24. No More Flutter<br />Custom Post Typesto create the special content<br />Custom Taxonomiesto organize the content<br />Custom Fieldsto get specific information on each post in a way that is human and pretty<br />
  25. 25. Thanks!<br />Questions?<br /><br />