• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Custom Post Types - What, Why, and How
 

Custom Post Types - What, Why, and How

on

  • 2,939 views

 

Statistics

Views

Total Views
2,939
Views on SlideShare
2,918
Embed Views
21

Actions

Likes
2
Downloads
19
Comments
1

4 Embeds 21

http://us-w1.rockmelt.com 12
http://lanyrd.com 4
http://www.linkedin.com 3
http://a0.twimg.com 2

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

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Thank you for posting the slides here. I have your presentation video up on wordpress.tv in one window whilst going through the slides here as you speak. Neat!
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Custom Post Types - What, Why, and How Custom Post Types - What, Why, and How Presentation Transcript

  • Custom Post Types What, Why, and How Heather Acton | WordCamp Detroit 2011 | 11.13.2011
  • Intro• “Ex” Mechanical Engineer turned WordPress developer• Started ActonWeb in 2009 by accident• Organizer of WordCamp Chicago, extended into monthly meetup with 2 chapters (so far)• Recently co-founded Lake County Branding Heather Acton / @heatheracton78
  • Overview• What are CPTs?• Why use CPTs?• Common applications• How to implement CPTs Heather Acton / @heatheracton78
  • What are CPTs?• Just another WordPress post• Stored in same table (wp_posts) as WP default postsCustom Post Types are NOT:• Post Formats (see Mark Jacquith’s post) Heather Acton / @heatheracton78
  • Why use CPTs?• Vary the display of the single post and post archives vs. WP default posts• Simplify entry of detailed post information for the site owner Heather Acton / @heatheracton78
  • Default New Post Heather Acton / @heatheracton78
  • New Custom Post Typew/ Custom Meta Boxes Heather Acton / @heatheracton78
  • Common Applications• E-commerce products• Directories• Events• Movie / book reviews• Recipes• Portfolio items Heather Acton / @heatheracton78
  • How to Implement CPTs (AKA the most important slide) 1. Register your custom post type 2. Register any custom taxonomies 3. Add custom meta boxes to Edit Post screen (prettier custom fields) 4. Set up archives page template 5. Set up single post templateResource: Slides, Child Theme, & Snippets Heather Acton / @heatheracton78
  • Step 1: Register Your CPT• Use Custom Post Type UI plugin Heather Acton / @heatheracton78
  • Step 2:Register Custom Taxonomies • Use Custom Post Type UI plugin Heather Acton / @heatheracton78
  • Step 3:Add Custom Meta Boxes• Use Advanced Custom Fields plugin• Use Meta Box plugin Heather Acton / @heatheracton78
  • Heather Acton / @heatheracton78 Step 4:Set Up CPT Archives Template • Copy the contents of your main theme’s archives.php file in your theme folder • Create a new file in your child theme called archives-yourcptname.php and paste the contents into that file • Add <?php /* Template Name: YOURCPTNAME Archive */ ?> to the top of your new archives file • Right before the loop in your new archives file, paste: <?php $loop = new WP_Query( array( post_type => yourcptname, posts_per_page => 10 ) ); ?> • Change the loop statement to: <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> • Create a new page via your WordPress dashboard, fill in the title with your desired page title, and select “YOURCPTNAME Archive” as your page template • Once you have published posts of your custom post type, visit http:// yoursitename.com/yourcptname to see your working CPT archive page
  • Notes on Creating CPT Archive Template• These steps will provide the same archive display as your standard post archives• Add additional parameters to the array to display posts in a certain order, display number of posts per page, etc.• Theme frameworks that alter WP core functions alter this process Heather Acton / @heatheracton78
  • Step 5:Set Up Single Post Template • Copy the contents of your current single.php file in your main theme folder • Create a new file called single-yourcptname.php in your child theme folder and paste the contents into that file • Replace the part of the loop that calls for the content and comments with calls for your custom fields that you generated • Meta-box plugin has great support on how to call each type of custom field Heather Acton / @heatheracton78
  • Bonus Step:Celebrate Your New Superpower Heather Acton / @heatheracton78
  • Watchouts• Naming best practices for CPTs (see Codex)• Theme frameworks that alter WP core functions (Genesis)• Custom taxonomy names that conflict with your CPT names or other taxonomy names (i.e. your categories/tags) • see this forum post Heather Acton / @heatheracton78
  • Additional Resources• Slides, Child Theme, & Snippets• WordPress Codex | Post Types• Custom Post Types in WP by Justin Tadlock• WordPress Custom Post Types Guide• Genesis Specific • Custom Post Types with Genesis • How to Create a Custom Template in Genesis • StudioPress forums Heather Acton / @heatheracton78