SlideShare uma empresa Scribd logo
1 de 18
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 posts


Custom 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 Type
w/ 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 template

Resource: 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

Mais conteúdo relacionado

Mais procurados

Wordcamp 2010 Themes for Beginners
Wordcamp 2010 Themes for BeginnersWordcamp 2010 Themes for Beginners
Wordcamp 2010 Themes for Beginners
Bonnie Vasko
 
Taking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the LimitTaking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the Limit
Josh Guffey
 

Mais procurados (13)

Keeping Your Themes and Plugins Organized.
Keeping Your Themes and Plugins Organized.Keeping Your Themes and Plugins Organized.
Keeping Your Themes and Plugins Organized.
 
There's No Crying In Wordpress! (an intro to WP)
There's No Crying In Wordpress! (an intro to WP)There's No Crying In Wordpress! (an intro to WP)
There's No Crying In Wordpress! (an intro to WP)
 
Intro To WordPress Themes
Intro To WordPress ThemesIntro To WordPress Themes
Intro To WordPress Themes
 
Wordcamp 2010
Wordcamp 2010Wordcamp 2010
Wordcamp 2010
 
Wordcamp 2010 Themes for Beginners
Wordcamp 2010 Themes for BeginnersWordcamp 2010 Themes for Beginners
Wordcamp 2010 Themes for Beginners
 
Making Your Own URL Shortening Service
Making Your Own URL Shortening ServiceMaking Your Own URL Shortening Service
Making Your Own URL Shortening Service
 
WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1
 
Wordpress Tech Talk at Atlogys
Wordpress Tech Talk at AtlogysWordpress Tech Talk at Atlogys
Wordpress Tech Talk at Atlogys
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
 
Joomla! Installation
Joomla! InstallationJoomla! Installation
Joomla! Installation
 
Building on the Microsoft Graph: App in 60 minutes
Building on the Microsoft Graph: App in 60 minutesBuilding on the Microsoft Graph: App in 60 minutes
Building on the Microsoft Graph: App in 60 minutes
 
Taking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the LimitTaking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the Limit
 
Installing WordPress The Right Way
Installing WordPress The Right WayInstalling WordPress The Right Way
Installing WordPress The Right Way
 

Semelhante a Custom Post Types - What, Why, and How

Workshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress pluginWorkshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress plugin
ylefebvre
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
Stephanie Leary
 
Custom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealCustom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp Montreal
Joey Kudish
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
K.Adam White
 

Semelhante a Custom Post Types - What, Why, and How (20)

Starting WordPress Theme Review
Starting WordPress Theme ReviewStarting WordPress Theme Review
Starting WordPress Theme Review
 
Equity WordPress framework with Chad and Dave
Equity WordPress framework with Chad and DaveEquity WordPress framework with Chad and Dave
Equity WordPress framework with Chad and Dave
 
Content-Driven WordPress Development - WordCamp Omaha 2014
Content-Driven WordPress Development - WordCamp Omaha 2014Content-Driven WordPress Development - WordCamp Omaha 2014
Content-Driven WordPress Development - WordCamp Omaha 2014
 
Workshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress pluginWorkshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress plugin
 
The Flexibility of WordPress
The Flexibility of WordPressThe Flexibility of WordPress
The Flexibility of WordPress
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
Custom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealCustom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp Montreal
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
 
Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?
 
Week 5 open session
Week 5 open sessionWeek 5 open session
Week 5 open session
 
Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016
 
Newbies guide to customizing word press themes 25
Newbies guide to customizing word press themes 25Newbies guide to customizing word press themes 25
Newbies guide to customizing word press themes 25
 
MDST 3703 F10 Studio 10
MDST 3703 F10 Studio 10MDST 3703 F10 Studio 10
MDST 3703 F10 Studio 10
 
Wordpress theme development
Wordpress theme developmentWordpress theme development
Wordpress theme development
 
Custom post types - WordPress
Custom post types - WordPressCustom post types - WordPress
Custom post types - WordPress
 
Using Custom Post Types and Advanced Custom Fields with Elementor
 Using Custom Post Types and Advanced Custom Fields with Elementor Using Custom Post Types and Advanced Custom Fields with Elementor
Using Custom Post Types and Advanced Custom Fields with Elementor
 
WordPress - Open Source Overview Presentation
WordPress - Open Source Overview PresentationWordPress - Open Source Overview Presentation
WordPress - Open Source Overview Presentation
 
The Genesis Framework: Hooks & Filters for Theme Development
The Genesis Framework: Hooks & Filters for Theme DevelopmentThe Genesis Framework: Hooks & Filters for Theme Development
The Genesis Framework: Hooks & Filters for Theme Development
 
WordPress Complete Tutorial
WordPress Complete TutorialWordPress Complete Tutorial
WordPress Complete Tutorial
 
เพาเวอร์พอย Wordpress3 5-1
เพาเวอร์พอย Wordpress3 5-1เพาเวอร์พอย Wordpress3 5-1
เพาเวอร์พอย Wordpress3 5-1
 

Mais de Heather Acton (7)

Framework Overview - Genesis
Framework Overview - GenesisFramework Overview - Genesis
Framework Overview - Genesis
 
Developing a Website with WordPress
Developing a Website with WordPressDeveloping a Website with WordPress
Developing a Website with WordPress
 
WordPress Crash Course
WordPress Crash CourseWordPress Crash Course
WordPress Crash Course
 
WordPress Crash Course - WP 101
WordPress Crash Course - WP  101WordPress Crash Course - WP  101
WordPress Crash Course - WP 101
 
The Digital Eco System
The Digital Eco SystemThe Digital Eco System
The Digital Eco System
 
How To Be a Nonprofit Social Media Rockstar
How To Be a Nonprofit Social Media RockstarHow To Be a Nonprofit Social Media Rockstar
How To Be a Nonprofit Social Media Rockstar
 
Nonprofits - Get Your Blog On!
Nonprofits - Get Your Blog On!Nonprofits - Get Your Blog On!
Nonprofits - Get Your Blog On!
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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
  • 6. Default New Post 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
  • 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

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n