SlideShare una empresa de Scribd logo
1 de 28
1




          Custom Post Types
                 Now What?
                           By Cody Helgeson
                      WordCamp Phoenix 2012




    @codyhelgeson | @fallingupmedia | #wcphx
2




    Find More Info

     Who Am I?
     My Experience with WordPress

     @codyhelgeson
     @fallingupmedia
     fallingupmedia.com
     cody@fallingupmedia.com




           @codyhelgeson | @fallingupmedia | #wcphx
3




    Topics For The Day
     • Custom Post Type Best Practices
     • Custom Taxonomies
     • Page Templates
     • Custom Fields
     • Custom Admin Columns
     • Custom Queries




           @codyhelgeson | @fallingupmedia | #wcphx
4




    Custom Post Types

     • Who has or is about to use custom post types?
     • Why use custom post types
     • Why not?
     • For the client
     • For the developer




            @codyhelgeson | @fallingupmedia | #wcphx
5




    Custom Post Types
    Examples

     • Book and Product Reviews
     • Job and Business Listings
     • Events and Locations
     • Portfolios and Case Studies
     • Combine with BuddyPress for Community Domination!
     • Anything your Heart Desires....



            @codyhelgeson | @fallingupmedia | #wcphx
6




     Custom Post Types
     The Code

    http://codex.wordpress.org/Function_Reference/register_post_type

        • Contextual help menus are a nice touch
        • Permalinks matter!
        • Flush the rewrite rules, or save permalink settings
        • /%category%/%postname%/
        • www.domain.com/custom-post-type/post-title



               @codyhelgeson | @fallingupmedia | #wcphx
7




    Topics For The Day

     • Custom Post Type Best Practices
     • Custom Taxonomies
     • Page Templates
     • Custom Fields
     • Custom Admin Columns
     • Custom Queries



           @codyhelgeson | @fallingupmedia | #wcphx
8




    Custom Taxonomies

             http://codex.wordpress.org/Taxonomies


     • Categorizes and groups content
     • Hierarchal or not? I.E. tags or categories
     • Clean and intuitive for users
     • Custom slugs argument
     • Create custom page templates and queries


            @codyhelgeson | @fallingupmedia | #wcphx
9




     Custom Taxonomies
     The Code

    http://codex.wordpress.org/Function_Reference/register_taxonomy

        • Flush rewrite or save permalink settings
        • There are reserved terms!
        • register_taxonomy($taxonomy, $object_type, $args); 




               @codyhelgeson | @fallingupmedia | #wcphx
10




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
11




     Page Templates
          http://codex.wordpress.org/Template_Hierarchy


      • WordPress makes it easy! Use them!
      • single-post_type.php
      • archive-post_type.php
      • taxonomy-taxonomy_name-slug.php
      • taxonomy-taxonomy_name.php


            @codyhelgeson | @fallingupmedia | #wcphx
12




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
13




     Custom Fields
             http://codex.wordpress.org/Custom_Fields


      • Purely incredible! Endless possibilities
      • Remove what you don’t need from editor. Take the time
      • Create your own or use a plugin
        • Advanced Custom Fields plugin
        • Magic Fields plugin
      • get_post_meta - add_post_meta

             @codyhelgeson | @fallingupmedia | #wcphx
14




     Custom Fields
     Examples



        • Real world examples on the web......




            @codyhelgeson | @fallingupmedia | #wcphx
15




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
16




     Custom Admin Columns
     The Code

 http://codex.wordpress.org/Plugin_API/Action_Reference/
 manage_posts_custom_column

 http://codex.wordpress.org/Plugin_API/Filter_Reference/
 manage_edit-post_type_columns


 add_action("manage_posts_custom_column", "your_custom_post_column_function");

 add_filter("manage_edit-$post_type_columns", "your_custom_column_function");




               @codyhelgeson | @fallingupmedia | #wcphx
17



 http://blog.elliotcondon.com/wordpress/advanced-custom-fields-
 admin-custom-columns/


     function my_page_columns($columns)
     {
     " $columns = array(
     " " 'cb'" " => '<input type="checkbox" />',
     " " 'thumbnail'" =>"'Thumbnail',
     " " 'title' " => 'Title',
     " " 'featured' "=> 'Featured',
     " " 'author'" =>"'Author',
     " " 'date'" " =>"'Date',
     " );
     " return $columns;
     }




                 @codyhelgeson | @fallingupmedia | #wcphx
18


     function my_custom_columns($column)
     {
     " global $post;
     " if($column == 'thumbnail')
     " {
     " " echo wp_get_attachment_image( get_field('page_image', $post->ID), array(200,200) );
     " }
     " elseif($column == 'featured')
     " {
     " " if(get_field('featured'))
     " " {
     " " " echo 'Yes';
     " " }
     " " else
     " " {
     " " " echo 'No';
     " " }
     " }
     }
      
     add_action("manage_pages_custom_column", "my_custom_columns");
     add_filter("manage_edit-page_columns", "my_page_columns");



                    @codyhelgeson | @fallingupmedia | #wcphx
19




     Custom Admin Columns
     Examples




           @codyhelgeson | @fallingupmedia | #wcphx
20




 http://www.trymypoolguy.com

     function my_post_columns_forums($columns)
     {
     " $columns = array(
     " " 'cb'" " => '<input type="checkbox" />',
     " " 'title' " => 'Listing Title',
     " " 'featured'" => 'Featured',
     " " 'author'      => 'Author',
     " " 'comments' => '<img src="image_path_goes_here" />',
     " " 'zips'     => 'Zip Code',
     " " 'services'       => 'Services',
     " " 'repairs'      => 'Repairs',
     " " 'date'" " => 'Date',
     " );
     " return $columns;
     }




                @codyhelgeson | @fallingupmedia | #wcphx
21
     function my_custom_columns_forums($column)
     {
     "   global $post;
     "   if($column == 'featured')
     "   {
     "   "     if(get_field('featured'))
     "   "     {
     "   "     "    echo '<strong>Yes</strong>';
     "   "     }
     "   "     else
     "   "     {
     "   "     "    echo '';
     "   "     }
     "   }
     "   if($column == 'zips')
     "   {
     "   "     echo get_field('zip_code', $post->ID);
     "   }
     "   if($column == 'services')
     "   {
     "     $custom_fields = get_post_custom($post->ID);
     "     $my_custom_field = $custom_fields['services'];
     "     foreach ( $my_custom_field as $key => $value )
     "       echo $value . "<br />";
     "   }
     "   if($column == 'repairs')
     "   {
     "     $custom_fields = get_post_custom($post->ID);
     "     $my_custom_field = $custom_fields['repairs'];
     "     foreach ( $my_custom_field as $key => $value )
     "       echo $value . "<br />";
     "   }
22




     Custom Admin Columns
     Examples




           @codyhelgeson | @fallingupmedia | #wcphx
23




     Topics For The Day
     Custom Post Types

       • Custom Post Type Best Practices
       • Custom Taxonomies
       • Page Templates
       • Custom Fields
       • Custom Admin Columns
       • Custom Queries



             @codyhelgeson | @fallingupmedia | #wcphx
24




     Custom Queries
       http://codex.wordpress.org/Template_Tags/get_posts
      http://codex.wordpress.org/Class_Reference/WP_Query


      • get_posts
        • does not modify global variables
      • wp_query
        • always <?php wp_reset_query(); ?>




            @codyhelgeson | @fallingupmedia | #wcphx
25




     Custom Queries
     get posts from:
     custom post type - dogfood
     and category = brand
      <?php
      $args = array(
         'numberposts' => 8,
         'orderby' => 'rand',
         'post_type' => 'dogfood',
         'dogfood_category' => 'brand',
         'post_status' => 'publish'
      );
      $show_brands = get_posts ( $args );
      ?>




                  @codyhelgeson | @fallingupmedia | #wcphx
26




     Custom Queries
     Examples



        • Real world examples on the web......




            @codyhelgeson | @fallingupmedia | #wcphx
27




     Thank You!

      @codyhelgeson
      @fallingupmedia
      fallingupmedia.com
      cody@fallingupmedia.com




            @codyhelgeson | @fallingupmedia | #wcphx
28




           Custom Post Types
                  Now What?
                            By Cody Helgeson
                       WordCamp Phoenix 2012




     @codyhelgeson | @fallingupmedia | #wcphx

Más contenido relacionado

La actualidad más candente

Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
kevinvw
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
chriseppstein
 

La actualidad más candente (12)

Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Rails
 
Lose Your Head! Re-imagining WordPress's Role in Content Presentation
Lose Your Head! Re-imagining WordPress's Role in Content PresentationLose Your Head! Re-imagining WordPress's Role in Content Presentation
Lose Your Head! Re-imagining WordPress's Role in Content Presentation
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
 
Understanding the ins and outs of word press metadata
Understanding the ins and outs of word press metadataUnderstanding the ins and outs of word press metadata
Understanding the ins and outs of word press metadata
 
The Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web DevelopmentThe Transparent Web: Bridging the Chasm in Web Development
The Transparent Web: Bridging the Chasm in Web Development
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
 
HTML5: Introduction
HTML5: IntroductionHTML5: Introduction
HTML5: Introduction
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
 
Styling Components with JavaScript: MelbCSS Edition
Styling Components with JavaScript: MelbCSS EditionStyling Components with JavaScript: MelbCSS Edition
Styling Components with JavaScript: MelbCSS Edition
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
WAI-ARIA is More Than Accessibility
WAI-ARIA is More Than AccessibilityWAI-ARIA is More Than Accessibility
WAI-ARIA is More Than Accessibility
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 

Similar a Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson

Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Coding
inspector_fegter
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
Stephanie Leary
 

Similar a Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson (20)

WordPress 3 Custom Post Types
WordPress 3 Custom Post TypesWordPress 3 Custom Post Types
WordPress 3 Custom Post Types
 
Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Coding
 
WordPress: A Designer's CMS
WordPress: A Designer's CMSWordPress: A Designer's CMS
WordPress: A Designer's CMS
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
Theme Development from the Coding End
Theme Development from the Coding EndTheme Development from the Coding End
Theme Development from the Coding End
 
Dev Theming
Dev ThemingDev Theming
Dev Theming
 
Cain & Obenland — Episode 4
Cain & Obenland — Episode 4Cain & Obenland — Episode 4
Cain & Obenland — Episode 4
 
Wordpress beyond blogging
Wordpress beyond bloggingWordpress beyond blogging
Wordpress beyond blogging
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Carrington Core (2014)
Carrington Core (2014)Carrington Core (2014)
Carrington Core (2014)
 
Simple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress ThemeSimple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress Theme
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
WordPress 3.4 Theme Customizer
WordPress 3.4 Theme CustomizerWordPress 3.4 Theme Customizer
WordPress 3.4 Theme Customizer
 
What's New in WordPress 3.0 (for developers)
What's New in WordPress 3.0 (for developers)What's New in WordPress 3.0 (for developers)
What's New in WordPress 3.0 (for developers)
 
Custom Fields & Custom Metaboxes Overview
Custom Fields & Custom Metaboxes OverviewCustom Fields & Custom Metaboxes Overview
Custom Fields & Custom Metaboxes Overview
 
WP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesWP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post Types
 
Beyond Posts and Pages: Structured Content in WordPress
Beyond Posts and Pages: Structured Content in WordPressBeyond Posts and Pages: Structured Content in WordPress
Beyond Posts and Pages: Structured Content in WordPress
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016
 

Último

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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
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
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson

  • 1. 1 Custom Post Types Now What? By Cody Helgeson WordCamp Phoenix 2012 @codyhelgeson | @fallingupmedia | #wcphx
  • 2. 2 Find More Info Who Am I? My Experience with WordPress @codyhelgeson @fallingupmedia fallingupmedia.com cody@fallingupmedia.com @codyhelgeson | @fallingupmedia | #wcphx
  • 3. 3 Topics For The Day • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 4. 4 Custom Post Types • Who has or is about to use custom post types? • Why use custom post types • Why not? • For the client • For the developer @codyhelgeson | @fallingupmedia | #wcphx
  • 5. 5 Custom Post Types Examples • Book and Product Reviews • Job and Business Listings • Events and Locations • Portfolios and Case Studies • Combine with BuddyPress for Community Domination! • Anything your Heart Desires.... @codyhelgeson | @fallingupmedia | #wcphx
  • 6. 6 Custom Post Types The Code http://codex.wordpress.org/Function_Reference/register_post_type • Contextual help menus are a nice touch • Permalinks matter! • Flush the rewrite rules, or save permalink settings • /%category%/%postname%/ • www.domain.com/custom-post-type/post-title @codyhelgeson | @fallingupmedia | #wcphx
  • 7. 7 Topics For The Day • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 8. 8 Custom Taxonomies http://codex.wordpress.org/Taxonomies • Categorizes and groups content • Hierarchal or not? I.E. tags or categories • Clean and intuitive for users • Custom slugs argument • Create custom page templates and queries @codyhelgeson | @fallingupmedia | #wcphx
  • 9. 9 Custom Taxonomies The Code http://codex.wordpress.org/Function_Reference/register_taxonomy • Flush rewrite or save permalink settings • There are reserved terms! • register_taxonomy($taxonomy, $object_type, $args);  @codyhelgeson | @fallingupmedia | #wcphx
  • 10. 10 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 11. 11 Page Templates http://codex.wordpress.org/Template_Hierarchy • WordPress makes it easy! Use them! • single-post_type.php • archive-post_type.php • taxonomy-taxonomy_name-slug.php • taxonomy-taxonomy_name.php @codyhelgeson | @fallingupmedia | #wcphx
  • 12. 12 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 13. 13 Custom Fields http://codex.wordpress.org/Custom_Fields • Purely incredible! Endless possibilities • Remove what you don’t need from editor. Take the time • Create your own or use a plugin • Advanced Custom Fields plugin • Magic Fields plugin • get_post_meta - add_post_meta @codyhelgeson | @fallingupmedia | #wcphx
  • 14. 14 Custom Fields Examples • Real world examples on the web...... @codyhelgeson | @fallingupmedia | #wcphx
  • 15. 15 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 16. 16 Custom Admin Columns The Code http://codex.wordpress.org/Plugin_API/Action_Reference/ manage_posts_custom_column http://codex.wordpress.org/Plugin_API/Filter_Reference/ manage_edit-post_type_columns add_action("manage_posts_custom_column", "your_custom_post_column_function"); add_filter("manage_edit-$post_type_columns", "your_custom_column_function"); @codyhelgeson | @fallingupmedia | #wcphx
  • 17. 17 http://blog.elliotcondon.com/wordpress/advanced-custom-fields- admin-custom-columns/ function my_page_columns($columns) { " $columns = array( " " 'cb'" " => '<input type="checkbox" />', " " 'thumbnail'" =>"'Thumbnail', " " 'title' " => 'Title', " " 'featured' "=> 'Featured', " " 'author'" =>"'Author', " " 'date'" " =>"'Date', " ); " return $columns; } @codyhelgeson | @fallingupmedia | #wcphx
  • 18. 18 function my_custom_columns($column) { " global $post; " if($column == 'thumbnail') " { " " echo wp_get_attachment_image( get_field('page_image', $post->ID), array(200,200) ); " } " elseif($column == 'featured') " { " " if(get_field('featured')) " " { " " " echo 'Yes'; " " } " " else " " { " " " echo 'No'; " " } " } }   add_action("manage_pages_custom_column", "my_custom_columns"); add_filter("manage_edit-page_columns", "my_page_columns"); @codyhelgeson | @fallingupmedia | #wcphx
  • 19. 19 Custom Admin Columns Examples @codyhelgeson | @fallingupmedia | #wcphx
  • 20. 20 http://www.trymypoolguy.com function my_post_columns_forums($columns) { " $columns = array( " " 'cb'" " => '<input type="checkbox" />', " " 'title' " => 'Listing Title', " " 'featured'" => 'Featured', " " 'author' => 'Author', " " 'comments' => '<img src="image_path_goes_here" />', " " 'zips' => 'Zip Code', " " 'services' => 'Services', " " 'repairs' => 'Repairs', " " 'date'" " => 'Date', " ); " return $columns; } @codyhelgeson | @fallingupmedia | #wcphx
  • 21. 21 function my_custom_columns_forums($column) { " global $post; " if($column == 'featured') " { " " if(get_field('featured')) " " { " " " echo '<strong>Yes</strong>'; " " } " " else " " { " " " echo ''; " " } " } " if($column == 'zips') " { " " echo get_field('zip_code', $post->ID); " } " if($column == 'services') " { " $custom_fields = get_post_custom($post->ID); " $my_custom_field = $custom_fields['services']; " foreach ( $my_custom_field as $key => $value ) " echo $value . "<br />"; " } " if($column == 'repairs') " { " $custom_fields = get_post_custom($post->ID); " $my_custom_field = $custom_fields['repairs']; " foreach ( $my_custom_field as $key => $value ) " echo $value . "<br />"; " }
  • 22. 22 Custom Admin Columns Examples @codyhelgeson | @fallingupmedia | #wcphx
  • 23. 23 Topics For The Day Custom Post Types • Custom Post Type Best Practices • Custom Taxonomies • Page Templates • Custom Fields • Custom Admin Columns • Custom Queries @codyhelgeson | @fallingupmedia | #wcphx
  • 24. 24 Custom Queries http://codex.wordpress.org/Template_Tags/get_posts http://codex.wordpress.org/Class_Reference/WP_Query • get_posts • does not modify global variables • wp_query • always <?php wp_reset_query(); ?> @codyhelgeson | @fallingupmedia | #wcphx
  • 25. 25 Custom Queries get posts from: custom post type - dogfood and category = brand <?php $args = array( 'numberposts' => 8, 'orderby' => 'rand', 'post_type' => 'dogfood', 'dogfood_category' => 'brand', 'post_status' => 'publish' ); $show_brands = get_posts ( $args ); ?> @codyhelgeson | @fallingupmedia | #wcphx
  • 26. 26 Custom Queries Examples • Real world examples on the web...... @codyhelgeson | @fallingupmedia | #wcphx
  • 27. 27 Thank You! @codyhelgeson @fallingupmedia fallingupmedia.com cody@fallingupmedia.com @codyhelgeson | @fallingupmedia | #wcphx
  • 28. 28 Custom Post Types Now What? By Cody Helgeson WordCamp Phoenix 2012 @codyhelgeson | @fallingupmedia | #wcphx

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n