• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
WordPress 3 Custom Post Types
 

WordPress 3 Custom Post Types

on

  • 5,922 views

Using Custom Post Types with WordPress 3. Presented at WordCamp Victoria BC, May 15, 2010.

Using Custom Post Types with WordPress 3. Presented at WordCamp Victoria BC, May 15, 2010.

Statistics

Views

Total Views
5,922
Views on SlideShare
5,664
Embed Views
258

Actions

Likes
11
Downloads
0
Comments
0

8 Embeds 258

http://www.dazil.com 114
http://www.slideshare.net 68
http://www.mychoicedelhi.blogspot.in 41
http://mychoicedelhi.blogspot.in 20
http://mychoicedelhi.blogspot.com 11
http://mychoicedelhi.blogspot.fr 2
http://webcache.googleusercontent.com 1
http://feeds.feedburner.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

WordPress 3 Custom Post Types WordPress 3 Custom Post Types Presentation Transcript

  • Custom Post types in WordPress 3 Dave Zille May 15, 2010 - WordCamp Victoria BC
  • About Dave • President, dazil Internet Services • WordPress dev, WordPress conversions • web: dazil.com twitter: @dazil • Principal, Learn it Today • WordPress classroom and online training • web: learnittoday.ca twitter: @learnittodayca
  • Agenda • Custom Post Types: • What are they? What aren’t they? • Why do we need them? • Custom Post Type ideas/examples • Demo: • Creating a custom post type • Displaying a custom post type • Resources
  • WordPress 3: Not just for Blogs Anymore! The term “blog” has been replaced with “site” throughout WordPress 3 is (officially) an actual CMS! WordPress install process now asks for “Site Title”
  • Top 5 Reasons WP is a CMS:
  • Top 5 Reasons WP is a CMS: 1. Scalability
  • Top 5 Reasons WP is a CMS: 1. Scalability 2. Security
  • Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management
  • Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management 4. Custom Taxonomies
  • Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management 4. Custom Taxonomies 5. Custom Post Types
  • What are Custom Post Types? • Custom Post Types are “content” types • Not to be confused with “blog post” • Traditional “post” is actually just another Custom Post Type • Can be used to store and administer different types of content on your WordPress site • Traditionally done via plugins (Flutter, Pods, etc) • A huge part of why WP 3 is a CMS
  • What aren’t Custom Post Types? • Custom Post Types are not: • A replacement for Custom Fields • (used in conjunction with Custom Fields) • Completely GUI driven • (i.e. cannot be created with default WP GUI)
  • Why do we need Custom Post Types? • Because Custom Post Types: • Make it easy to create and edit different forms of content within WordPress • Eliminate the need to “fake” custom post types by using 3rd party plugins • Will make you and your clients happy!
  • Custom Post Type Examples • Media: • Video, Podcasts • Title,YouTube URL, Length/Duration, Captions, Show Notes, etc • Information: • Car for Sale • Make, Model, Color, Features, Pictures, etc..
  • Custom Post Type Examples • Information (cont’d) • Real Estate Listing • Price, # bed, # bath, amenities, photos, etc. • Gallery/Portfolio • Thumbnail, description, URL, etc. • Calendar of Events • Date, time, cost, location, etc.
  • Your First Custom Post Type
  • Your First Custom Post Type • Case Study:
  • Your First Custom Post Type • Case Study: • Recipe database
  • Your First Custom Post Type • Case Study: • Recipe database • Description
  • Your First Custom Post Type • Case Study: • Recipe database • Description • Ingredients
  • Your First Custom Post Type • Case Study: • Recipe database • Description • Ingredients • Prep Time
  • Your First Custom Post Type • Case Study: • Recipe database • Description • Ingredients • Prep Time • Cook Time
  • Custom Post Types: The Code • The register_post_type() function was introduced in WordPress 2.9 • WordPress 3 makes register_post_type() very useful • Minimal code, and a Custom Post Type is up and running: add_action( 'init', 'create_recipe_post_type' ); function create_recipe_post_type() { register_post_type( 'recipe', array( 'label' => __( 'Recipes' ), 'singular_label' => __( 'Recipe' ), 'public' => true, ) ); }
  • Custom Post Types: The Code
  • Custom Post Types: The Code • Where does the code go? • 2 options: • Create a plugin file, or • add to your theme’s functions.php
  • Custom Post Types: The Code • Where does the code go? • 2 options: • Create a plugin file, or • add to your theme’s functions.php • This is useful, but can I do more? • The register_post_type() function has 20+ arguments • Can control a lot about CP Types using them • Let’s review some of them..
  • Custom Post Types: The Code
  • Custom Post Types: The Code register_post_type() arguments • label • A plural descriptive name for the post type • eg “Recipes” • singular_label • A singular descriptive name for the post type • eg “Recipe”
  • Custom Post Types: The Code
  • Custom Post Types: The Code register_post_type() arguments • description • A short descriptive summary of what the post type is • eg. “A set of directions with a list of ingredients for making or preparing food.” • public • Whether or not the post type should be made available in the admin • boolean, default: false
  • Custom Post Types: The Code
  • Custom Post Types: The Code register_post_type() arguments • menu_position • Allows the positioning of the post type in the admin menu • Default: a new post type is added after Comments • menu_icon • Allows you to specify a custom icon for the post type • Default: posts icon
  • Custom Post Types: The Code
  • Custom Post Types: The Code register_post_type() arguments
  • Custom Post Types: The Code register_post_type() arguments • hierarchical
  • Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’)
  • Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false
  • Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false • can_export
  • Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false • can_export • Specifies whether posts of the post type can be exportable using WordPress’ export function
  • Custom Post Types: The Code register_post_type() arguments • hierarchical • Determines whether the post type is hierarchical (as in ‘pages’), or not (as in ‘posts’) • Default: false • can_export • Specifies whether posts of the post type can be exportable using WordPress’ export function • Default: true
  • Custom Post Types: The Code
  • Custom Post Types: The Code register_post_type() arguments
  • Custom Post Types: The Code register_post_type() arguments • supports
  • Custom Post Types: The Code register_post_type() arguments • supports • Defines what meta boxes and other fields appear when editing or creating a post
  • Custom Post Types: The Code register_post_type() arguments • supports • Defines what meta boxes and other fields appear when editing or creating a post • Options: title, editor, comments, trackbacks, revisions, author, excerpt, thumbnail, custom- fields, page-attributes
  • Custom Post Types: The Code register_post_type() arguments • supports • Defines what meta boxes and other fields appear when editing or creating a post • Options: title, editor, comments, trackbacks, revisions, author, excerpt, thumbnail, custom- fields, page-attributes • Default: title, editor
  • Custom Post Types: The Code
  • Custom Post Types: The Code register_post_type() arguments
  • Custom Post Types: The Code register_post_type() arguments • register_meta_box_cb
  • Custom Post Types: The Code register_post_type() arguments • register_meta_box_cb • taxonomies
  • Custom Post Types: The Code register_post_type() arguments • register_meta_box_cb • taxonomies • capability_type / capabilities
  • Custom Post Types: Displaying
  • Custom Post Types: Displaying • Customizing the custom post type template
  • Custom Post Types: Displaying • Customizing the custom post type template • single.php
  • Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default)
  • Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default) • single-post_type_name.php
  • Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default) • single-post_type_name.php • custom template for the custom post type
  • Custom Post Types: Displaying • Customizing the custom post type template • single.php • template for the custom post type (default) • single-post_type_name.php • custom template for the custom post type • eg. single-recipe.php
  • Custom Post Types: Displaying
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php:
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' );
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) {
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() )
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) );
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) ); return $query;
  • Custom Post Types: Displaying • Displaying custom post types on your site’s homepage • Add to your theme’s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) ); return $query; }
  • Other Custom Post Type Functions
  • Other Custom Post Type Functions • Get the “post type” of a post:
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id);
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type:
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) )
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.';
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.'; else
  • Other Custom Post Type Functions • Get the “post type” of a post: • get_post_type() allows you to check the post type of a specific post $post_type = get_post_type($post_id); • Check if a post is of a specific type: • is_post_type() allows you to check a specific post against a specific post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.'; else echo 'This is not a recipe.';
  • Resources • WordPress.org Codex: register_post_type function reference: • http://codex.wordpress.org/Function_Reference/register_post_type • Blog post: Custom post types in WordPress: • http://justintadlock.com/archives/2010/04/29/custom-post-types-in- wordpress • Blog post: First impressions of custom post type: • http://wpengineer.com/impressions-of-custom-post-type/ • Plugin: Custom post type UI plugin for WordPress • http://www.strangework.com/2010/03/03/custom-post-type-ui-plugin-for- wordpress/