Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Creatively Creating
Custom Post Types
NikhilVimal
#WordUpMPLS
Hi, I’m Nikhil
• I develop with WordPress
• I can be found on Twitter @TechVoltz
• This my first talk ever
Custom Post Types?
They Rock (Seriously)
But what are they?
•Instead of using default posts and categories in
WordPress, use Custom Post Types
•You can add a lot o...
Why Do You need them?
Organization
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
But how do we add
Custom Post Types?
With a plugin of course
Create a file called myposttype.php
<?php
/**
* Plugin Name: Your Custom Post Type
* Plugin URI: http://yourpluginswebsite...
add_action('init', 'wordup_sessions');
function wordup_sessions() {
$wordup_args = array(
'public' => true,
'has_archive' ...
Lets examine all the
code!!
add_action('init', 'wordup_sessions');
function wordup_sessions() {
$wordup_args = array(
'public' => true,
'has_archive' => true,
'query_var' => 'wordup',
'menu...
'labels' => array(
'name' => 'WordUp Sessions',
'singular' => 'WordUp Session',
'add_new' => 'Add Session',
'add_new_item'...
register_post_type('WordUp', $wordup_args );
}
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
After our Custom Post
type function….
add_action('init', 'wordup_tracks');
function wordup_tracks(){
$track_args = array(
'hierarchical' => true,
'query_var' => ‘wordup_tracks',
'show_tagcloud' => ...
'labels' => array(
'name' => 'Tracks',
'edit_item' => 'Edit Track',
'update_item' => 'Update Track',
'add_new_item' => 'Ad...
register_taxonomy(‘wordup_tracks',
array('wordup'), $dev_args);
}
The array(‘wordup’) is our custom post type
You can add more
Like Custom Fields
Questions?
Resources
• http://justintadlock.com/archives/2010/04/29/custom-post-types-in-
wordpress
• http://codex.wordpress.org/Post...
Thank You!
Nikhil Vimal
@TechVoltz
Creatively creating custom post types!
Creatively creating custom post types!
Creatively creating custom post types!
Creatively creating custom post types!
Prochain SlideShare
Chargement dans…5
×

Creatively creating custom post types!

206 vues

Publié le

Publié dans : Technologie, Business
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Creatively creating custom post types!

  1. 1. Creatively Creating Custom Post Types NikhilVimal #WordUpMPLS
  2. 2. Hi, I’m Nikhil • I develop with WordPress • I can be found on Twitter @TechVoltz • This my first talk ever
  3. 3. Custom Post Types? They Rock (Seriously)
  4. 4. But what are they? •Instead of using default posts and categories in WordPress, use Custom Post Types •You can add a lot of cool things that are not in a Default WordPress install •Added in WordPress 3.0
  5. 5. Why Do You need them? Organization
  6. 6. Portfolio Post Type could be paintings
  7. 7. Online Store Post Type could be Products
  8. 8. Your only limitation is Your imagination
  9. 9. “WordPress can hold and display many different types of content.” -WordPress Codex
  10. 10. But how do we add Custom Post Types? With a plugin of course
  11. 11. Create a file called myposttype.php <?php /** * Plugin Name: Your Custom Post Type * 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 */
  12. 12. add_action('init', 'wordup_sessions'); function wordup_sessions() { $wordup_args = array( 'public' => true, 'has_archive' => true, 'query_var' => 'wordup', 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), 'labels' => array( 'name' => 'WordUp Sessions', 'singular' => 'WordUp 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 WordUp', 'not_found' => 'No sessions found', 'not_found_in_trash' => 'No Sessions found in the Trash', ), ); register_post_type('WordUp', $wordup_args ); }
  13. 13. Lets examine all the code!!
  14. 14. add_action('init', 'wordup_sessions');
  15. 15. function wordup_sessions() { $wordup_args = array( 'public' => true, 'has_archive' => true, 'query_var' => 'wordup', 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
  16. 16. 'labels' => array( 'name' => 'WordUp Sessions', 'singular' => 'WordUp 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', ), );
  17. 17. register_post_type('WordUp', $wordup_args ); }
  18. 18. Styling your CPT Page With single-$posttype.php
  19. 19. Having an Archive Page for your CPT With archive-$posttype.php
  20. 20. Taxonomies More Organization
  21. 21. “Basically, a taxonomy is a way to group things together” -WordPress Codex
  22. 22. Taxonomies Categories and Tags
  23. 23. Portfolio Taxonomy is oil painting
  24. 24. After our Custom Post type function….
  25. 25. add_action('init', 'wordup_tracks');
  26. 26. function wordup_tracks(){ $track_args = array( 'hierarchical' => true, 'query_var' => ‘wordup_tracks', 'show_tagcloud' => true,
  27. 27. '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', ), );
  28. 28. register_taxonomy(‘wordup_tracks', array('wordup'), $dev_args); } The array(‘wordup’) is our custom post type
  29. 29. You can add more Like Custom Fields
  30. 30. Questions?
  31. 31. Resources • http://justintadlock.com/archives/2010/04/29/custom-post-types-in- wordpress • http://codex.wordpress.org/Post_Types • http://codex.wordpress.org/Taxonomies • http://wp.smashingmagazine.com/2012/11/08/complete-guide- custom-post-types/
  32. 32. Thank You! Nikhil Vimal @TechVoltz

×