SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Keeping Your Themes and Plugins Organized.
Keeping Your Themes and Plugins Organized.Keeping Your Themes and Plugins Organized.
Keeping Your Themes and Plugins Organized.Jacob Martella
 
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)Grace Solivan
 
Intro To WordPress Themes
Intro To WordPress ThemesIntro To WordPress Themes
Intro To WordPress Themesdamonsharp
 
Wordcamp 2010 Themes for Beginners
Wordcamp 2010 Themes for BeginnersWordcamp 2010 Themes for Beginners
Wordcamp 2010 Themes for BeginnersBonnie Vasko
 
Making Your Own URL Shortening Service
Making Your Own URL Shortening ServiceMaking Your Own URL Shortening Service
Making Your Own URL Shortening ServiceBob Hazlett
 
WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1David Bisset
 
Wordpress Tech Talk at Atlogys
Wordpress Tech Talk at AtlogysWordpress Tech Talk at Atlogys
Wordpress Tech Talk at AtlogysRitika Garga
 
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 #WRK2Curtiss Grymala
 
Joomla! Installation
Joomla! InstallationJoomla! Installation
Joomla! Installationghessler
 
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 minutesSPC Adriatics
 
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 LimitJosh Guffey
 
Installing WordPress The Right Way
Installing WordPress The Right WayInstalling WordPress The Right Way
Installing WordPress The Right WayChris Burgess
 

Tendances (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
 

Similaire à Custom Post Types - What, Why, and How

Starting WordPress Theme Review
Starting WordPress Theme ReviewStarting WordPress Theme Review
Starting WordPress Theme ReviewCatch Themes
 
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 DaveIDX Broker
 
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 2014Stephanie Eckles
 
Workshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress pluginWorkshop: Creating your first WordPress plugin
Workshop: Creating your first WordPress pluginylefebvre
 
The Flexibility of WordPress
The Flexibility of WordPressThe Flexibility of WordPress
The Flexibility of WordPressStephanie Eckles
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012Stephanie 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 MontrealJoey Kudish
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post TypesK.Adam White
 
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?Edmund Turbin
 
Week 5 open session
Week 5 open sessionWeek 5 open session
Week 5 open sessionRandall Rode
 
Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016David Brattoli
 
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 25New Tricks
 
Wordpress theme development
Wordpress theme developmentWordpress theme development
Wordpress theme developmentNaeem Junejo
 
Custom post types - WordPress
Custom post types - WordPressCustom post types - WordPress
Custom post types - WordPresskeithdevon
 
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 ElementorAngela Bowman
 
WordPress - Open Source Overview Presentation
WordPress - Open Source Overview PresentationWordPress - Open Source Overview Presentation
WordPress - Open Source Overview PresentationAndy Stratton
 
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 DevelopmentSarah Moyer
 

Similaire à 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
 

Plus de Heather Acton

Framework Overview - Genesis
Framework Overview - GenesisFramework Overview - Genesis
Framework Overview - GenesisHeather Acton
 
Developing a Website with WordPress
Developing a Website with WordPressDeveloping a Website with WordPress
Developing a Website with WordPressHeather Acton
 
WordPress Crash Course
WordPress Crash CourseWordPress Crash Course
WordPress Crash CourseHeather Acton
 
WordPress Crash Course - WP 101
WordPress Crash Course - WP  101WordPress Crash Course - WP  101
WordPress Crash Course - WP 101Heather Acton
 
The Digital Eco System
The Digital Eco SystemThe Digital Eco System
The Digital Eco SystemHeather Acton
 
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 RockstarHeather Acton
 
Nonprofits - Get Your Blog On!
Nonprofits - Get Your Blog On!Nonprofits - Get Your Blog On!
Nonprofits - Get Your Blog On!Heather Acton
 

Plus 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!
 

Dernier

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Dernier (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
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
  • 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

Notes de l'éditeur

  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