wordpress - create custom post types
DESCRIPTION
Explains wordpress custom posts types and how University of Central Florida's (UCF) Marketing web team creates custom post types.TRANSCRIPT
![Page 1: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/1.jpg)
Creating Custom Post TypesUCF Marketing
Brandon [email protected]
http://www.slideshare.net/DFieldFL/wordpress-create-custom-post-types
![Page 2: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/2.jpg)
OutlineUCF Marketing background
What are custom post types (CPTs)
How to create a CPTs
How to display CPTs
How we (SMCA) create CPTs
Conclusion
Questions/Comments
![Page 3: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/3.jpg)
UCF Marketing background
Web Development Team Roger Wolf Jo Greybill Brandon Groves
Been using WordPress for 5 Years
Develop ~12 sites a year
Sites we developed using WordPress http://www.ucf.edu http://today.ucf.edu http://pegasus.ucf.edu http://hr.ucf.edu http://hospitality.ucf.edu
![Page 4: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/4.jpg)
What are custom post types (CPTs)
Most content uses post types [1]
PostsPagesNavigation MenuAttachmentRevision
CPT
[1] http://codex.wordpress.org/Post_Types#Custom_Post_Types
![Page 5: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/5.jpg)
A way of organizing content Announcements People Documents
Add custom data Meta data Featured image Taxonomies
Remove fields Title Content
Meta data
![Page 6: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/6.jpg)
When creating CPTs you have to also create a way of displaying them
CPTs are NOT displayed anywhere by default (except via single.php)
![Page 7: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/7.jpg)
Has anyone used custom post types?
Other use-caseshttp://www.bard.edu/ccs/http://www.cec.fiu.edu/academics/bachelor/http://www.nicholls.edu/admission/http://pegasus.ucf.edu/
![Page 8: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/8.jpg)
How to create CPTsSelling ACME products
List all product that are sold Individual product page with
descriptions
Resourceshttp://codex.wordpress.org/Post_Typeshttp://codex.wordpress.org/
Function_Reference/register_post_typehttp://codex.wordpress.org/
Plugin_API/Action_Reference
![Page 9: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/9.jpg)
Reserved Post Types [2]
postpageattachmentrevisionnav_menu_item
Register CPT [2]
Post type ID (required)Arguments – defining characteristics of the CPT
[2] http://codex.wordpress.org/Function_Reference/register_post_type#Reserved_Post_Types
![Page 10: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/10.jpg)
Hook function into the workflowFunctions.php file is auto loaded [3]
Convenience method add_action [4] [5]
When to execute our codeWhat code to executePriority compared to other added actionsArguments
[3] http://codex.wordpress.org/Theme_Development#Functions_File[4] http://codex.wordpress.org/Function_Reference/add_action[5] http://codex.wordpress.org/Plugin_API/Action_Reference
![Page 11: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/11.jpg)
Code{theme}/functions.php
![Page 12: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/12.jpg)
CPT displays on left menu
Displays postsAdd new post
A CPT by default looks the same as Post
TitleContent/Body
![Page 13: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/13.jpg)
How to display CPTsCreate products
AnvilGiant Rubber Band
![Page 14: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/14.jpg)
Where are our products?
![Page 15: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/15.jpg)
Template structure [6]
A single page to display productsPages are automatically put into the menupage-{slug}.php filenameContent title is used for the slug
[6] http://codex.wordpress.org/Template_Hierarchy
![Page 16: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/16.jpg)
Creating our own display page
![Page 17: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/17.jpg)
Empty pageDefaults to page.php
![Page 18: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/18.jpg)
Create templateusing the page slug file naming convention
(page-products.php)Querie our CPT of amce_products (The Loop) [7]
[7] http://codex.wordpress.org/The_Loop
The Loop
![Page 19: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/19.jpg)
Products page
![Page 20: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/20.jpg)
View a productDefaults to single.php [6]
[6] http://codex.wordpress.org/Template_Hierarchy
![Page 21: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/21.jpg)
Create a custom displayDisplaying single CTP (single-{post-type-id}.php) [6]
[6] http://codex.wordpress.org/Template_Hierarchy
![Page 22: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/22.jpg)
Displaying single CTP (single-acme_product.php)
![Page 23: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/23.jpg)
How we (SMCA) create CPTs
Resourceshttps://github.com/UCF/Wordpress-Generic-Theme
Codecustom-post-types.php (Base CPT Class)
![Page 24: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/24.jpg)
Defining a new CPT (Document) Inherit CustomePostType classModify variables if needed
![Page 25: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/25.jpg)
Defining a new CPTAdd custom functionality
![Page 26: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/26.jpg)
Enabling CPT (registering)Add CPT class name to the Config’s
custom_post_types array (functions/config.php)
![Page 27: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/27.jpg)
How we (SMCA) create CPTs
![Page 28: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/28.jpg)
ConclusionWordPress is more than a blogging tool
CPTs help group like content
CPTs are NOT displayed by defaultManually link to itCreate a display page listing CPTs (page
templates)Create unique single post display (post templates)
![Page 29: WordPress - Create Custom Post Types](https://reader033.vdocuments.net/reader033/viewer/2022061300/54c714d14a7959ae708b45e1/html5/thumbnails/29.jpg)
Questions?
http://www.slideshare.net/DFieldFL/wordpress-create-custom-post-types
Contact: [email protected]