SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Creatively Creating
Custom Post Types
Nikhil Vimal
#WordSesh2
Hi, I’m Nikhil (NikV)
• I develop with WordPress
• I can be found on Twitter @TechVoltz
• Core contributor for WordPress 3.7
Custom Post Types?
They Rock (Seriously)
But what are Custom Post Types?

An example of a post type is posts
and pages
Portfolio
Post Type could be paintings
Online Store
Post Type could be Products
Your only limitation is
Your imagination
“WordPress can hold and display many different
types of content.”

-WordPress Codex
Custom Post types should
be added with…
A plugin of course
Create a file called myposttype.php
<?php
/**
* Plugin Name: Your Custom Post Type plugin
* Plugin URI: http://yourpluginswebsite.com
* Description: A brief description of your Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Your Name
* Author URI: http://yourwebsite.com
* License: A "Slug" license name e.g. GPL2
*/
add_action('init', 'wordsesh_sessions');
function wordsesh_sessions() {
$wordsesh_args = array(
'public' => true,
'query_var' => 'wordsesh',
‘can_export’ => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'page-attributes' ),

'labels' => array(
'name' => 'WordSesh 2 Sessions',
'singular' => 'WordSesh 2 Session',
'add_new' => 'Add Session',
'add_new_item' => 'Add Session',
'edit_item' => 'Edit Session',
'new_item' => 'New Session',
'view_item' => 'View Session',
'search_items' => 'Search Sessions',
'not_found' => 'No sessions found',
'not_found_in_trash' => 'No Sessions found in the Trash',
),
);
register_post_type('WordSesh', $wordsesh_args );
}
Now lets add to our
Custom Post Type
Custom meta data
With meta boxes
Let’s add a meta box
function add_cpt_metabox(){
add_meta_box('cpt_meta', 'Speaker Meta Box', 'cpt_meta',
'wordsesh','side', 'default');
}
add_action('add_meta_boxes', 'add_cpt_metabox');
'<input type="text" name=“cpt_meta" value="' . $cpt_meta . '"
class="widefat" />';
You can also use…
User roles and Capabilities with
Custom Post Types
function delete_wordseshcpt_menu() {
if( !current_user_can( 'administrator' ) ):
remove_menu_page('edit.php?post_type=wordsesh');
endif;
}
add_action('admin_menu', 'delete_wordseshcpt_menu');
Capabilities with Custom Post Types
Adding Capabilities to roles
Templates
For Custom Post Types
Styling your CPT Page
With single-$posttype.php
Having an Archive Page for
your CPT
With archive-$posttype.php
Taxonomies
More Organization
“Basically, a taxonomy is a way to group things
together”

-WordPress Codex
Taxonomies
Categories and Tags
Portfolio
Taxonomy is oil painting
add_action('init','wordsesh_tracks‘);
function wordsesh_tracks(){
$tracks_args = array(
'hierarchical' => true,
'query_var' => 'tracks',
'show_tagcloud' => true,
'labels' => array(
'name' => 'Tracks',
'edit_item' => 'Edit Track',
'update_item' => 'Update Track',
'add_new_item' => 'Add New Track',
'new_item_name' => 'New Track',
'all_items' => 'All Tracks',
'search_items' => 'Search Tracks',
'popular_items' => 'Popular Tracks',
'add_or_remove_items' => 'Add or remove Tracks',
'choose_from_most_used' => 'Choose from most used Tracks',
),
);
register_taxonomy('tracks',
array('wordsesh'), $tracks_args);

The array(‘wordsesh’) is our custom post type
Resources
• http://justintadlock.com/archives/2010/04/29/custom-post-types-inwordpress
• http://codex.wordpress.org/Post_Types
• http://codex.wordpress.org/Taxonomies
• http://wp.smashingmagazine.com/2012/11/08/complete-guidecustom-post-types/
Thank You!
Nikhil Vimal (NikV)
@TechVoltz

Más contenido relacionado

Destacado

Adobe phonegap-workshop-2013
Adobe phonegap-workshop-2013Adobe phonegap-workshop-2013
Adobe phonegap-workshop-2013
Haig Armen
 

Destacado (7)

Adobe phonegap-workshop-2013
Adobe phonegap-workshop-2013Adobe phonegap-workshop-2013
Adobe phonegap-workshop-2013
 
TOC Workshop 2013
TOC Workshop 2013TOC Workshop 2013
TOC Workshop 2013
 
Design Driven & Agile
Design Driven & AgileDesign Driven & Agile
Design Driven & Agile
 
Midwest UX Mobile Workshop 2012
Midwest UX Mobile Workshop 2012Midwest UX Mobile Workshop 2012
Midwest UX Mobile Workshop 2012
 
Designing Mineblock: Merging Physical & Digital to create Meta Products
Designing Mineblock: Merging Physical & Digital to create Meta ProductsDesigning Mineblock: Merging Physical & Digital to create Meta Products
Designing Mineblock: Merging Physical & Digital to create Meta Products
 
Client is a human too
Client is a human tooClient is a human too
Client is a human too
 
Responsive Workflow, Break the rules or die
Responsive Workflow, Break the rules or dieResponsive Workflow, Break the rules or die
Responsive Workflow, Break the rules or die
 

Similar a Creatively creating custom post types! word sesh2

Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
techvoltz
 
Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
techvoltz
 
Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
techvoltz
 
Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
techvoltz
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
K.Adam White
 
Building a Portfolio With Custom Post Types
Building a Portfolio With Custom Post TypesBuilding a Portfolio With Custom Post Types
Building a Portfolio With Custom Post Types
Alex Blackie
 
Webinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedWebinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting Started
MongoDB
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
Yoav Farhi
 
Extending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post TypesExtending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post Types
Utsav Singh Rathour
 

Similar a Creatively creating custom post types! word sesh2 (20)

Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
 
Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
 
Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
 
Creatively creating custom post types!
Creatively creating custom post types!Creatively creating custom post types!
Creatively creating custom post types!
 
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
 
Custom content types &amp; custom taxonomies in wordpress
Custom content types &amp; custom taxonomies in wordpressCustom content types &amp; custom taxonomies in wordpress
Custom content types &amp; custom taxonomies in wordpress
 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
 
Building a Portfolio With Custom Post Types
Building a Portfolio With Custom Post TypesBuilding a Portfolio With Custom Post Types
Building a Portfolio With Custom Post Types
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Custom Post Types in WP3
Custom Post Types in WP3Custom Post Types in WP3
Custom Post Types in WP3
 
Webinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedWebinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting Started
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Extending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post TypesExtending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post Types
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
 
Custom Post Types and Meta Fields
Custom Post Types and Meta FieldsCustom Post Types and Meta Fields
Custom Post Types and Meta Fields
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
ITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell Toolmaking
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 

Último

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
Safe Software
 
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
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
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
Victor Rentea
 

Último (20)

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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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
 
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
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Creatively creating custom post types! word sesh2