WordPress - Create Custom Post Types

Post on 27-Jan-2015

126 views 1 download

Tags:

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

Creating Custom Post TypesUCF Marketing

Brandon Groveswebcom@ucf.edu

http://www.slideshare.net/DFieldFL/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

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

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

A way of organizing content Announcements People Documents

Add custom data Meta data Featured image Taxonomies

Remove fields Title Content

Meta data

When creating CPTs you have to also create a way of displaying them

CPTs are NOT displayed anywhere by default (except via single.php)

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/

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

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

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

Code{theme}/functions.php

CPT displays on left menu

Displays postsAdd new post

A CPT by default looks the same as Post

TitleContent/Body

How to display CPTsCreate products

AnvilGiant Rubber Band

Where are our products?

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

Creating our own display page

Empty pageDefaults to page.php

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

Products page

View a productDefaults to single.php [6]

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

Create a custom displayDisplaying single CTP (single-{post-type-id}.php) [6]

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

Displaying single CTP (single-acme_product.php)

How we (SMCA) create CPTs

Resourceshttps://github.com/UCF/Wordpress-Generic-Theme

Codecustom-post-types.php (Base CPT Class)

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

Defining a new CPTAdd custom functionality

Enabling CPT (registering)Add CPT class name to the Config’s

custom_post_types array (functions/config.php)

How we (SMCA) create CPTs

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)

Questions?

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

Contact: webcom@ucf.edu