Advanced Custom Post Types

Post on 28-Jan-2015

109 views 0 download

Tags:

description

My presentation at WordCamp San Diego 2013 about advanced methods of using custom post types and taxonomies.

transcript

AdvancedCustom Post Types

& TaxonomiesWordCamp San Diego 2013

#wcsd@theandystratton

Saturday, March 23, 13

Who am I?

Saturday, March 23, 13

Freelance WordPress Developer

Saturday, March 23, 13

Founder

Saturday, March 23, 13

What areCustom Post Types?

Saturday, March 23, 13

Generic Post ContentInherit core user interface

& functionality

Saturday, March 23, 13

Including:Post meta, attachments, featured image,

hierarchies, comments, etc.

Saturday, March 23, 13

What areCustom Taxonomies?

Saturday, March 23, 13

Generic Tags/Categories

Saturday, March 23, 13

Taxonomies create relationships

between content

Saturday, March 23, 13

Why should we use them?

Saturday, March 23, 13

In the old days, we’d:Re-purpose blog postsfiltering by category/tag

Saturday, March 23, 13

In the old days, we’d:Create custom database tables and functionality

Saturday, March 23, 13

In the old days, we’d:Use strange plugins

and non-standard code

Saturday, March 23, 13

This is pretty muchdoing it wrong.

Saturday, March 23, 13

Why DO we custom post types/taxonomies?

Saturday, March 23, 13

Future compatible

Saturday, March 23, 13

WordPress Coding Standards

Saturday, March 23, 13

Theme & Plugin compatibility(page ordering, SEO plugins, etc.)

Saturday, March 23, 13

Flexible & ExtendiblePost Meta, attachments,

hierarchies, ordering, featured images

Saturday, March 23, 13

Help maintain a consistent user-interface

&consistent user-experience

Saturday, March 23, 13

@alternatekev:“Build design systems.”

Saturday, March 23, 13

For what can we use custom post types?

Saturday, March 23, 13

Home Page Sliders

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Photo Galleries

Saturday, March 23, 13

Locations

Saturday, March 23, 13

Job Postings

Saturday, March 23, 13

People/Teams

Saturday, March 23, 13

Reusable Static Content

Saturday, March 23, 13

HTML Emails

Saturday, March 23, 13

Let’s break thesesite elements down into

CPT components.

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Callout Boxesimage

Saturday, March 23, 13

Callout Boxesimage

content

Saturday, March 23, 13

Element Post Type Element

Image Featured Image

Content Post Title/Content

LinkIn post content, ORcustom field

Callout Boxes

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

Callout Boxes

Saturday, March 23, 13

More Post Type Maps

Saturday, March 23, 13

Element Post Type Element

Image Gallery Post Attachments

Title Post Title

Description Post Content

Date Post Date

Photo Gallery

Saturday, March 23, 13

Element Post Type Element

Photo Featured Image

Person Name Post Title

Description Post Content

Additional Info(Title, Phone, etc.)

Custom Fields/Post Meta

People/Teams

Saturday, March 23, 13

This gives us somegreat benefits...

Saturday, March 23, 13

Content SchedulingUse publish date and

the Post Expirator pluginwordpress.org/extend/plugins/post-expirator/

Saturday, March 23, 13

Content Staging LibrarySave callouts as drafts.

Easily swap content with more options than text widgets.

Saturday, March 23, 13

Benefits Case StudyMarketing Sliders for Brick Bodies

Saturday, March 23, 13

Marketing TeamAnyone with publish capabilities can create, schedule and expire slides.

Saturday, March 23, 13

Monthly PlansPlan their specials/events in advance

Set their next month’s slides to publish when current expire

Saturday, March 23, 13

WordPress StandardsConsistent UI & user experience

If a user can add/edit a post, they can add/edit a slide

Saturday, March 23, 13

WordPress StandardsFuture compatible

Compatible with plugins(e.g. post expirator)

Saturday, March 23, 13

Enhancing the Core UI

Saturday, March 23, 13

Enhancing the Core UI We should add context to everything.

Add logical elements to make managing content easier.

Saturday, March 23, 13

Enter Title Here

Saturday, March 23, 13

Easy Code

https://gist.github.com/theandystratton/5225881

Saturday, March 23, 13

Custom Menu Icons

Saturday, March 23, 13

Custom Menu Icons

https://gist.github.com/theandystratton/5226783

Saturday, March 23, 13

Admin Columns

Saturday, March 23, 13

Custom Columns

https://gist.github.com/theandystratton/5225903

Saturday, March 23, 13

Custom Column Contenthttps://gist.github.com/theandystratton/5225903

Saturday, March 23, 13

Saturday, March 23, 13

Make Great ExperiencesMeet user expectations

(clicking the thumbnail edits the post)Show all relevant data

Saturday, March 23, 13

Taxonomy: Store Categories

Can group/relate contentFilter the edit screen

Saturday, March 23, 13

Clicking Entertainment in the “Store Categories” column filters listing by locations tagged “Entertainment.”

Saturday, March 23, 13

Saturday, March 23, 13

Using “show_admin_column” when registering a public taxonomy.

gist.github.com/theandystratton/5226656

Saturday, March 23, 13

Add Context with Taxonomies

Case Study: Content Tags

Saturday, March 23, 13

General TagsApplied to pages, posts and

all custom post types

Saturday, March 23, 13

Create relationships acrossall post types

Easily relate unrelated content

Saturday, March 23, 13

Example:LIIFund.org

Saturday, March 23, 13

Some pages are content about specific types of projects.

Saturday, March 23, 13

Custom post type of “statistics” used to populate the left sidebar column

Saturday, March 23, 13

Client wants “Child Care” statistics to auto-populate in the sidebar of the child care page

Saturday, March 23, 13

Saturday, March 23, 13

Page

Saturday, March 23, 13

Page

Custom Post Type

Saturday, March 23, 13

Used content tags to relate pages to statistics

& pull programmatically.

Saturday, March 23, 13

Saturday, March 23, 13

Saturday, March 23, 13

wp_dropdown_categories()

Saturday, March 23, 13

These content tags allow users to tag content and we can use it to

provide contextual content.

Saturday, March 23, 13

https://gist.github.com/theandystratton/5226712

Saturday, March 23, 13

https://gist.github.com/theandystratton/5226712

Saturday, March 23, 13

You can pair content tags(a generic taxonomy)with content blocks(a generic post type)

to rapidly deploy all sorts of contextual content management.

Saturday, March 23, 13

Content Blockshttps://github.com/szbl/szbl-content-blocks/

Content Tagshttps://github.com/szbl/szbl-content-tags/

Saturday, March 23, 13

Be Extendible!Think Like Core.Be Like Core.

Saturday, March 23, 13

HooksDo Actions.Apply Filters.

Saturday, March 23, 13

What if I want to hide the admin column and only apply these to pages and posts?

Saturday, March 23, 13

We can hook into Content Tags like this:

Saturday, March 23, 13

Truly Extendible.You can customize code.

You can re-use code.

Saturday, March 23, 13

Your plugins folder may look like this:

Saturday, March 23, 13

Your plugins folder may look like this:

This plugin...

Saturday, March 23, 13

Your plugins folder may look like this:

This plugin...Modifies

theseplugins

Saturday, March 23, 13

Truly Extendible.You can customize code.

You can re-use code.

Saturday, March 23, 13

Saves time.Saves money.

Updates are easier.Functionality is not

tethered to a theme.

Saturday, March 23, 13

Some Final DOs & DON’Ts

Saturday, March 23, 13

DON’TAlter/change core

user-interface(CSS, Javascript, core hacks)

Saturday, March 23, 13

DON’TRe-brand WordPress as your

own custom CMS.(You’re not fooling anyone.)

Saturday, March 23, 13

DON’TUse custom tables or

database queries whenit is not necessary.

(In most cases, it’s not.)

Saturday, March 23, 13

DON’TForget about widgets, sidebars and menus.

Saturday, March 23, 13

DON’TOvercomplicate Shit.

(Complicate shit whenshit gets complicated.)

Saturday, March 23, 13

DOUse the Core UI

Saturday, March 23, 13

DOCreate additional UI

elements via Core CSS.Let core inspire you.

Saturday, March 23, 13

DOPlace your code into plugins.Even custom themes need plugin love.

Saturday, March 23, 13

DOConstantly improve

your code.

Saturday, March 23, 13

DORe-use your code.

Saturday, March 23, 13

DOWrite extendible code.Use Actions and Filters.

Saturday, March 23, 13

DOShare your code.

WP.org/GitHub/Gist/your blog

Saturday, March 23, 13

DOBe awesome.

Love what you do. Do it well.

Saturday, March 23, 13

Thanks for the time.

Saturday, March 23, 13