This document discusses custom post types in WordPress. It explains that custom post types allow varying the display of single posts and archives compared to default posts. Common uses include e-commerce products, directories, events, and more. It provides steps to implement custom post types, including registering the post type and taxonomies, adding custom fields, and creating archives and single templates.
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Custom Post Types - What, Why, and How
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 posts
Custom 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
7. New Custom Post Type
w/ 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 template
Resource: 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
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