Successfully reported this slideshow.
Your SlideShare is downloading. ×

Custom Post Types and Taxonomies

Ad

Custom Post Types & Taxonomies<br />WordPress just got CMSier<br />

Ad

Who Am I?<br />I am a self-taught designer and programmer with over 5 years of experience working with a variety of busine...

Ad

What is a Post Type?<br />Posts and pages and more! Oh my!<br />

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Loading in …3
×

Check these out next

1 of 31 Ad
1 of 31 Ad
Advertisement

More Related Content

Advertisement
Advertisement

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 designer and programmer with over 5 years of experience working with a variety of businesses, non-profits, and individuals.<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 while also working a full time gig at blr | further as a UI Developer.<br /> TammyHartDesigns.com tammy@tammyhartdesigns.com @tammyhart<br />
  3. 3. What is a Post Type?<br />Posts and pages and more! Oh my!<br />
  4. 4. How Do They Work?<br />Should be called “Content Types”<br />Content goes into the posts table<br />Each content item is assigned a post_type<br />The queries output the content<br /> The default post type is ‘post’<br />
  5. 5. Built in Types<br />Main Content<br />Post – blog style content<br />Page – static content<br />Other<br />Attachment – any images or other files uploaded to a post (of any type)<br />Revision – an archive of versions of a particular post<br />Nav Menu Item – Used in the new menu system<br />
  6. 6. Custom Types<br />Employees<br />Products<br />… any content that needs to be stored and used differently than blog posts or static pages<br />Won’t show up in main RSS feed<br />
  7. 7. What Isn’t a Post Type?<br />Asides and galleries and links! Oh my!<br />
  8. 8. Post Formats<br />Coming in WordPress 3.1<br />Think Tumblr, not post types<br />More like post’s post types, not different content types<br />Will show up in main RSS feed<br />
  9. 9. More Information<br />Post Formats - WordPress.org Codexhttp://bit.ly/formats01<br />Post Formats vs. Custom Post Types – Mark Jaquithhttp://bit.ly/formats02<br />What, Whys, and How To’sof Post Formats in WordPress 3.1 – WP Beginnerhttp://bit.ly/formats03<br />Post types and formats and taxonomies, oh my! - Ottohttp://bit.ly/formats04<br />
  10. 10. What Is a taxonomy?<br />Read my lips, now new taxonomies<br />
  11. 11. 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 />
  12. 12. Built in Taxonomies<br />Post Taxonomies<br />Category<br />Post Tag<br />Other<br />Link Category<br />Nav Menu<br />
  13. 13. Custom Taxonomies<br />Employee departments<br />Product categories<br />… any way you want to tag or categorize your custom post types<br />Can be used with blog posts and static pages as well<br />Multiple taxonomy query coming in WordPress 3.1<br />Use Query Multiple Taxonomies plugin<br />
  14. 14. Hand Coding<br />The hard way<br />
  15. 15. 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 WPEngineer.org<br />http://bit.ly/posttypes<br />
  16. 16. 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 WPEngineer.org<br />http://bit.ly/posttypes<br />
  17. 17. 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 WPEngineer.org<br />http://bit.ly/posttypes<br />
  18. 18. Using Plugins<br />The easy way<br />
  19. 19. “<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 />
  20. 20. 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 />
  21. 21. 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 />
  22. 22. Custom Templates<br />Now what do I do?<br />
  23. 23. Template Hierarchy<br />Custom Post Type<br />single-{post_type}.php<br />single.php<br />index.php<br />Custom Post Types Display<br />Coming in version 3.1<br />Use Simple Custom Post Type Archives plugin<br />Custom Taxonomy<br />taxonomy-{taxonomy}-{term}.php<br />taxonomy-{taxonomy}.php<br />taxonomy.php<br />archive.php<br />index.php<br />
  24. 24. Custom Loops & Queries<br />This gets hardcore<br />
  25. 25. 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 />
  26. 26. 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 />
  27. 27. More Custom Content<br />But wait, there’s more!<br />
  28. 28. “<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 />
  29. 29. No More Flutter<br />Custom Post Types<br />to create the special content<br />Custom Taxonomies<br />to organize the content<br />Custom Fields<br />to get specific information on each post in a way that is human and pretty<br />
  30. 30. Customized Custom Fields<br />Plugins<br />More Fields<br />Builds pretty boxes with custom types of custom fields<br />Works perfectly with More Types and More Taxonomies<br />Custom fields<br />Widget-like interface<br />Doesn’t seem to interact with custom post types<br />Easy Custom Fields<br />Just as much coding as the hand coded method<br />… not so easy<br />Hand Coded<br />add_meta_box()<br />Basically limitless<br />Lots o’ code<br />WordPress.org Codexhttp://bit.ly/metabox01<br />Tutorial at Deluxe Blog Tipshttp://bit.ly/metabox02<br />We Function Tutorialhttp://bit.ly/metabox03<br />
  31. 31. Thanks!<br />Questions?<br />TammyHartDesigns.comtammy@tammyhartdesigns.com@tammyhart<br />

×