Wp meetup custom post types

3,831
-1

Published on

Slides from my Vancouver WordPress Meetup presentation, March 31st, 2011

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,831
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • The header text can be replaced with this simple block of code. Simple…
  • Wp meetup custom post types

    1. 1. Custom Post Types in WordPress 3.x<br />Setup, Customization and Useage Scenarios<br />Morten Rand-Hendriksen<br />Creative Director, Pink & Yellow Media<br />www.designisphilosophy.com<br />Twitter: @mor10<br />HELLO,MY NAME IS MOR10people tend to spell it with an ‘o’, but that’s just plain wrong<br />
    2. 2. WordPress Developers Unite!<br />!<br />Not your regular WordCamp<br />Speakers announced today<br />Tickets: $85www.wordcampdevelopers.com<br />
    3. 3. Like “regular” WordPress posts, but handled separately.<br />Custom single template<br />Custom index page<br />Custom taxonomies (categories and tags)<br />Custom taxonomy indexes<br />Advanced custom queries<br />WHAT ARE CUSTOM POST TYPES<br />?<br />
    4. 4.
    5. 5. CREATING A NEW CUSTOM POST TYPE<br />#<br />
    6. 6. // Add new post type for Shoots<br />add_action('init', 'adley_shoots_init');<br />function adley_shoots_init() {<br /> $labels = array( … stuff … );<br /> $args = array( … stuff … ); <br />register_post_type('shoot',$args);<br />}<br />CREATING A NEW CUSTOM POST TYPE<br />#<br />
    7. 7. $labels = array(<br /> 'name' => _x('Shoots', 'general name'),<br /> 'singular_name' => _x('Shoot', 'singular name'),<br /> 'add_new' => _x('Add new shoot', 'shoot'),<br /> 'add_new_item' => __('Add new shoot'),<br /> 'edit_item' => __('Edit shoot'),<br /> 'new_item' => __('New shoot'),<br /> 'view_item' => __('View shoot'),<br /> 'search_items' => __('Search shoots'),<br /> 'not_found' => __('No shoots found'),<br /> 'not_found_in_trash' => __('No shoots found in trash'), <br /> 'parent_item_colon' => ''<br /> );<br />CREATING A NEW CUSTOM POST TYPE<br />#<br />
    8. 8. $args = array(<br /> 'labels' => $labels,<br /> 'public' => true,<br /> 'publicly_queryable' => true,<br /> 'show_ui' => true, <br /> 'query_var' => true,<br /> 'rewrite' => true,<br /> 'capability_type' => 'post',<br /> 'hierarchical' => false,<br /> 'menu_position' => null,<br /> 'supports' => array('title','editor','author','thumbnail','excerpt','comments'),<br /> 'has_archive' => 'shoots'<br /> ); <br />CREATING A NEW CUSTOM POST TYPE<br />#<br />
    9. 9. CREATING A NEW CUSTOM POST TYPE<br />#<br />
    10. 10.
    11. 11.
    12. 12.
    13. 13. CREATING CUSTOM TAXONOMIES<br />#<br />
    14. 14. // Add taxonomies for Shoots<br />add_action( 'init', 'adley_create_taxonomies', 0 );<br />function adley_create_taxonomies() {<br /> $labels = array( … stuff …); <br />register_taxonomy('topics','shoot',array(<br /> … stuff <br /> )<br /> );<br />}<br />CREATING CUSTOM TAXONOMIES<br />#<br />
    15. 15. $labels = array(<br />'name' => _x( 'Topics', 'taxonomy general name' ),<br />'singular_name' => _x( 'Topic', 'taxonomy singular name' ),<br />'search_items' => __( 'Search by topic' ),<br />'all_items' => __( 'All topics' ),<br />'most_used_items' => null,<br />'parent_item' => null,<br />'parent_item_colon' => null,<br />'edit_item' => __( 'Change topic' ), <br />'update_item' => __( 'Update topic' ),<br />'add_new_item' => __( 'Add new topic' ),<br />'new_item_name' => __( 'New topic' ),<br />'menu_name' => __( 'Topics' ),<br />);<br />CREATING CUSTOM TAXONOMIES<br />#<br />
    16. 16. register_taxonomy('topics','shoot',array(<br />'hierarchical' => true,<br />'labels' => $labels,<br />'show_ui' => true,<br />'query_var' => true,<br />'rewrite' => array('slug' => 'topics' )<br />));<br />CREATING CUSTOM TAXONOMIES<br />#<br />
    17. 17.
    18. 18.
    19. 19. CUSTOM POST TYPE ICONS<br />?<br />
    20. 20. http://randyjensenonline.com/thoughts/<br />wordpress-custom-post-type-fugue-icons/<br />
    21. 21.
    22. 22. // Adds custom icon to the Shoots tab<br />add_action( 'admin_head', 'cpt_icons' );<br />function cpt_icons() {<br /> ?><br /> <style type="text/css" media="screen"><br /> #menu-posts-shoot .wp-menu-image {<br /> background: url(<?phpbloginfo('template_url') ?>/images/photo-album.png) no-repeat 6px – 17px !important;<br /> }<br /> #menu-posts-shoot:hover .wp-menu-image, #menu-posts-shoot.wp-has-current-submenu .wp-menu-image {<br /> background-position:6px 7px!important;<br /> }<br /> </style><br /><?php<br />}<br />CUSTOM POST TYPE ICONS<br />#<br />
    23. 23. // Adds custom icon to the Shoots tab<br />add_action( 'admin_head', 'cpt_icons' );<br />function cpt_icons() {<br /> ?><br /> <style type="text/css" media="screen"><br /> #menu-posts-shoot .wp-menu-image {<br /> background: url(<?phpbloginfo('template_url')?>/images/photo-album.png) no-repeat 6px – 17px !important;<br /> }<br /> #menu-posts-shoot:hover .wp-menu-image, #menu-posts-shoot.wp-has-current-submenu .wp-menu-image {<br /> background-position:6px 7px!important;<br /> }<br /> </style><br /><?php<br />}<br />CUSTOM POST TYPE ICONS<br />#<br />
    24. 24. // Adds custom icon to the Shoots tab<br />add_action( 'admin_head', 'cpt_icons' );<br />function cpt_icons() {<br /> ?><br /> <style type="text/css" media="screen"><br /> #menu-posts-shoot .wp-menu-image {<br /> background: url(<?phpbloginfo('template_url')?>/images/photo-album.png) no-repeat 6px – 17px !important;<br /> }<br /> #menu-posts-shoot:hover .wp-menu-image, #menu-posts-shoot.wp-has-current-submenu .wp-menu-image {<br /> background-position:6px 7px!important;<br /> }<br /> </style><br /><?php<br />}<br />CUSTOM POST TYPE ICONS<br />#<br />
    25. 25. For single pages:<br />single-postType.php<br />For taxonomy pages:<br />taxonomy.php<br />For index page(s) (new in 3.1):<br />archive-postType.php<br />CUSTOM POST TYPE PAGES<br />?<br />
    26. 26. $args = array(<br /> 'labels' => $labels,<br /> 'public' => true,<br /> 'publicly_queryable' => true,<br /> 'show_ui' => true, <br /> 'query_var' => true,<br /> 'rewrite' => true,<br /> 'capability_type' => 'post',<br /> 'hierarchical' => false,<br /> 'menu_position' => null,<br /> 'supports' => array('title','editor','author','thumbnail','excerpt','comments'),<br /> 'has_archive' => 'shoots'<br /> ); <br />CUSTOM POST TYPE PAGES<br />?<br />
    27. 27. CUSTOM POST TYPE PAGES<br />?<br />
    28. 28. CUSTOM POST TYPE PAGES<br />?<br />
    29. 29. CUSTOM POST TYPE PAGES<br />?<br />
    30. 30. CUSTOM POST TYPE PAGES<br />?<br />
    31. 31.
    32. 32.
    33. 33.
    34. 34. single-soknad.php<br />archive-soknad.php<br />taxonomy.php<br />
    35. 35. “FUN” WITH QUERIES<br />#<br />
    36. 36.
    37. 37.
    38. 38.
    39. 39. Get the object term (taxonomy value)<br /><?php<br />$terms = wp_get_object_terms( <br />$post->ID, <br />'soknadsstatus', <br />'fields=names‘<br />);<br />$status = implode(', ', $terms);<br />?><br />“FUN” WITH QUERIES<br />#<br />Taxonomy slug<br />all, ids, names or all_with_object_id<br />
    40. 40.
    41. 41. Create list if term items (categories)<br /><?php<br />$kommuneterm = get_terms('kommune', 'orderby=name‘); ?><br /><ul><br /><?phpforeach ($kommuneterm as $sted) { ?><br /><li><a href=“<?php echo get_term_link( $sted->slug, 'kommune‘ );?>"><br /><?phpecho $sted->name; ?> (<?php echo $sted->count; ?>)</a></li><br /><?php} ?><br /></ul><br />“FUN” WITH QUERIES<br />#<br />
    42. 42. EXPAND YOUR HORIZONS<br />?<br />Make Web Not WarSaturday May 7th<br />www.webnotwar.ca<br />
    43. 43. WordPress Developers Unite!<br />!<br />Not your regular WordCamp<br />Speakers announced today<br />Tickets: $85www.wordcampdevelopers.com<br />
    44. 44. Morten Rand-Hendriksen<br />Creative Director, Pink & Yellow Media<br />www.designisphilosophy.com<br />@mor10<br />www.pinkandyellow.com<br />designisphilosophy.com/facebook<br />GETINTOUCH<br />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×