WordPress - Create Custom Post Types

29
Creating Custom Post Types UCF Marketing Brandon Groves [email protected] http://www.slideshare.net/DFieldFL/wordpress-create-custom-post-type

description

Explains wordpress custom posts types and how University of Central Florida's (UCF) Marketing web team creates custom post types.

Transcript of WordPress - Create Custom Post Types

Page 1: WordPress - Create Custom Post Types

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

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

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

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

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

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

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

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

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

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

Code{theme}/functions.php

Page 12: WordPress - Create Custom Post Types

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

How to display CPTsCreate products

AnvilGiant Rubber Band

Page 14: WordPress - Create Custom Post Types

Where are our products?

Page 15: WordPress - Create Custom Post Types

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

Creating our own display page

Page 17: WordPress - Create Custom Post Types

Empty pageDefaults to page.php

Page 18: WordPress - Create Custom Post Types

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

Products page

Page 20: WordPress - Create Custom Post Types

View a productDefaults to single.php [6]

[6] http://codex.wordpress.org/Template_Hierarchy

Page 21: WordPress - Create Custom Post Types

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

Displaying single CTP (single-acme_product.php)

Page 23: WordPress - Create Custom Post Types

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

Defining a new CPT (Document) Inherit CustomePostType classModify variables if needed

Page 25: WordPress - Create Custom Post Types

Defining a new CPTAdd custom functionality

Page 26: WordPress - Create Custom Post Types

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

How we (SMCA) create CPTs

Page 28: WordPress - Create Custom Post Types

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

Questions?

http://www.slideshare.net/DFieldFL/wordpress-create-custom-post-types

Contact: [email protected]