Your SlideShare is downloading. ×
Custom Post Types - What, Why, and How
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Custom Post Types - What, Why, and How

2,791
views

Published on

Published in: Technology

1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,791
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. Custom Post Types What, Why, and How Heather Acton | WordCamp Detroit 2011 | 11.13.2011
    • 2. 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
    • 3. Overview• What are CPTs?• Why use CPTs?• Common applications• How to implement CPTs Heather Acton / @heatheracton78
    • 4. 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
    • 5. 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
    • 6. Default New Post Heather Acton / @heatheracton78
    • 7. New Custom Post Typew/ Custom Meta Boxes Heather Acton / @heatheracton78
    • 8. Common Applications• E-commerce products• Directories• Events• Movie / book reviews• Recipes• Portfolio items Heather Acton / @heatheracton78
    • 9. 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
    • 10. Step 1: Register Your CPT• Use Custom Post Type UI plugin Heather Acton / @heatheracton78
    • 11. Step 2:Register Custom Taxonomies • Use Custom Post Type UI plugin Heather Acton / @heatheracton78
    • 12. Step 3:Add Custom Meta Boxes• Use Advanced Custom Fields plugin• Use Meta Box plugin Heather Acton / @heatheracton78
    • 13. 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
    • 14. 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
    • 15. 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
    • 16. Bonus Step:Celebrate Your New Superpower Heather Acton / @heatheracton78
    • 17. 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
    • 18. 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