SlideShare uma empresa Scribd logo
1 de 78
Custom Post types
 in WordPress 3
             Dave Zille
  May 15, 2010 - WordCamp Victoria BC
About Dave
ā€¢ President, dazil Internet Services
  ā€¢ WordPress dev, WordPress conversions
   ā€¢   web: dazil.com   twitter: @dazil

ā€¢ Principal, Learn it Today
  ā€¢ WordPress classroom and online training
   ā€¢   web: learnittoday.ca twitter: @learnittodayca
Agenda
ā€¢   Custom Post Types:
    ā€¢   What are they? What arenā€™t they?

    ā€¢   Why do we need them?

ā€¢   Custom Post Type ideas/examples

ā€¢   Demo:

    ā€¢   Creating a custom post type

    ā€¢   Displaying a custom post type

ā€¢   Resources
WordPress 3: Not just for Blogs Anymore!

The term ā€œblogā€ has been
  replaced with ā€œsiteā€
       throughout

WordPress 3 is (ofļ¬cially)
  an actual CMS!

WordPress install process
now asks for ā€œSite Titleā€
Top 5 Reasons WP is a CMS:
Top 5 Reasons WP is a CMS:

1. Scalability
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
3. Menu Management
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
3. Menu Management
4. Custom Taxonomies
Top 5 Reasons WP is a CMS:

1. Scalability
2. Security
3. Menu Management
4. Custom Taxonomies
5. Custom Post Types
What are Custom Post Types?
ā€¢ Custom Post Types are ā€œcontentā€ types
  ā€¢   Not to be confused with ā€œblog postā€

      ā€¢   Traditional ā€œpostā€ is actually just another Custom
          Post Type

  ā€¢   Can be used to store and administer different
      types of content on your WordPress site
      ā€¢   Traditionally done via plugins (Flutter, Pods, etc)

      ā€¢   A huge part of why WP 3 is a CMS
What arenā€™t Custom Post Types?

ā€¢ Custom Post Types are not:
  ā€¢   A replacement for Custom Fields

      ā€¢   (used in conjunction with Custom Fields)

  ā€¢   Completely GUI driven

      ā€¢   (i.e. cannot be created with default WP GUI)
Why do we need
         Custom Post Types?
ā€¢ Because Custom Post Types:
 ā€¢ Make it easy to create and edit different
    forms of content within WordPress
  ā€¢ Eliminate the need to ā€œfakeā€ custom post
    types by using 3rd party plugins
  ā€¢ Will make you and your clients happy!
Custom Post Type Examples
ā€¢ Media:
 ā€¢ Video, Podcasts
   ā€¢   Title,YouTube URL, Length/Duration, Captions,
       Show Notes, etc

ā€¢ Information:
 ā€¢ Car for Sale
   ā€¢   Make, Model, Color, Features, Pictures, etc..
Custom Post Type Examples
ā€¢   Information (contā€™d)

    ā€¢ Real Estate Listing
     ā€¢   Price, # bed, # bath, amenities, photos, etc.

    ā€¢ Gallery/Portfolio
     ā€¢   Thumbnail, description, URL, etc.

    ā€¢ Calendar of Events
     ā€¢   Date, time, cost, location, etc.
Your First Custom Post Type
Your First Custom Post Type

ā€¢   Case Study:
Your First Custom Post Type

ā€¢   Case Study:

    ā€¢ Recipe database
Your First Custom Post Type

ā€¢   Case Study:

    ā€¢ Recipe database
     ā€¢   Description
Your First Custom Post Type

ā€¢   Case Study:

    ā€¢ Recipe database
     ā€¢   Description

     ā€¢   Ingredients
Your First Custom Post Type

ā€¢   Case Study:

    ā€¢ Recipe database
     ā€¢   Description

     ā€¢   Ingredients

     ā€¢   Prep Time
Your First Custom Post Type

ā€¢   Case Study:

    ā€¢ Recipe database
     ā€¢   Description

     ā€¢   Ingredients

     ā€¢   Prep Time

     ā€¢   Cook Time
Custom Post Types: The Code
 ā€¢    The register_post_type() function was introduced in
      WordPress 2.9

 ā€¢    WordPress 3 makes register_post_type() very useful

 ā€¢    Minimal code, and a Custom Post Type is up and running:
add_action( 'init', 'create_recipe_post_type' );

function create_recipe_post_type() {

   register_post_type( 'recipe',

   
   array(

   
   'label' => __( 'Recipes' ),

   
   'singular_label' => __( 'Recipe' ),

   
   'public' => true,

   
   )

   );
}
Custom Post Types: The Code
Custom Post Types: The Code
ā€¢   Where does the code go?

    ā€¢   2 options:

         ā€¢   Create a plugin ļ¬le, or

         ā€¢   add to your themeā€™s functions.php
Custom Post Types: The Code
ā€¢   Where does the code go?

    ā€¢   2 options:

            ā€¢   Create a plugin ļ¬le, or

            ā€¢   add to your themeā€™s functions.php

ā€¢   This is useful, but can I do more?

    ā€¢   The register_post_type() function has 20+ arguments

        ā€¢   Can control a lot about CP Types using them

        ā€¢   Letā€™s review some of them..
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments

ā€¢   label

    ā€¢   A plural descriptive name for the post type

        ā€¢   eg ā€œRecipesā€

ā€¢   singular_label

    ā€¢   A singular descriptive name for the post type

        ā€¢   eg ā€œRecipeā€
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments

ā€¢   description

    ā€¢   A short descriptive summary of what the post type is

        ā€¢   eg. ā€œA set of directions with a list of ingredients for making
            or preparing food.ā€

ā€¢   public

    ā€¢   Whether or not the post type should be made available in the
        admin

        ā€¢   boolean, default: false
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments

ā€¢   menu_position

    ā€¢   Allows the positioning of the post type in the admin menu

        ā€¢   Default: a new post type is added after Comments

ā€¢   menu_icon

    ā€¢   Allows you to specify a custom icon for the post type

        ā€¢   Default: posts icon
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments
Custom Post Types: The Code
register_post_type() arguments

ā€¢   hierarchical
Custom Post Types: The Code
register_post_type() arguments

ā€¢   hierarchical

    ā€¢   Determines whether the post type is hierarchical (as in ā€˜pagesā€™),
        or not (as in ā€˜postsā€™)
Custom Post Types: The Code
register_post_type() arguments

ā€¢   hierarchical

    ā€¢   Determines whether the post type is hierarchical (as in ā€˜pagesā€™),
        or not (as in ā€˜postsā€™)

        ā€¢   Default: false
Custom Post Types: The Code
register_post_type() arguments

ā€¢   hierarchical

    ā€¢   Determines whether the post type is hierarchical (as in ā€˜pagesā€™),
        or not (as in ā€˜postsā€™)

        ā€¢   Default: false

ā€¢   can_export
Custom Post Types: The Code
register_post_type() arguments

ā€¢   hierarchical

    ā€¢   Determines whether the post type is hierarchical (as in ā€˜pagesā€™),
        or not (as in ā€˜postsā€™)

        ā€¢   Default: false

ā€¢   can_export

    ā€¢   Speciļ¬es whether posts of the post type can be exportable using
        WordPressā€™ export function
Custom Post Types: The Code
register_post_type() arguments

ā€¢   hierarchical

    ā€¢   Determines whether the post type is hierarchical (as in ā€˜pagesā€™),
        or not (as in ā€˜postsā€™)

        ā€¢   Default: false

ā€¢   can_export

    ā€¢   Speciļ¬es whether posts of the post type can be exportable using
        WordPressā€™ export function

        ā€¢   Default: true
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments
Custom Post Types: The Code
register_post_type() arguments

ā€¢   supports
Custom Post Types: The Code
register_post_type() arguments

ā€¢   supports

    ā€¢   Deļ¬nes what meta boxes and other ļ¬elds appear when editing
        or creating a post
Custom Post Types: The Code
register_post_type() arguments

ā€¢   supports

    ā€¢   Deļ¬nes what meta boxes and other ļ¬elds appear when editing
        or creating a post

        ā€¢   Options: title, editor, comments, trackbacks,
            revisions, author, excerpt, thumbnail, custom-
            ļ¬elds, page-attributes
Custom Post Types: The Code
register_post_type() arguments

ā€¢   supports

    ā€¢   Deļ¬nes what meta boxes and other ļ¬elds appear when editing
        or creating a post

        ā€¢   Options: title, editor, comments, trackbacks,
            revisions, author, excerpt, thumbnail, custom-
            ļ¬elds, page-attributes

        ā€¢   Default: title, editor
Custom Post Types: The Code
Custom Post Types: The Code
register_post_type() arguments
Custom Post Types: The Code
register_post_type() arguments

ā€¢   register_meta_box_cb
Custom Post Types: The Code
register_post_type() arguments

ā€¢   register_meta_box_cb

ā€¢   taxonomies
Custom Post Types: The Code
register_post_type() arguments

ā€¢   register_meta_box_cb

ā€¢   taxonomies

ā€¢   capability_type / capabilities
Custom Post Types: Displaying
Custom Post Types: Displaying
ā€¢   Customizing the custom post type
    template
Custom Post Types: Displaying
ā€¢   Customizing the custom post type
    template

    ā€¢   single.php
Custom Post Types: Displaying
ā€¢   Customizing the custom post type
    template

    ā€¢   single.php

        ā€¢   template for the custom post type (default)
Custom Post Types: Displaying
ā€¢   Customizing the custom post type
    template

    ā€¢   single.php

        ā€¢   template for the custom post type (default)

    ā€¢   single-post_type_name.php
Custom Post Types: Displaying
ā€¢   Customizing the custom post type
    template

    ā€¢   single.php

        ā€¢   template for the custom post type (default)

    ā€¢   single-post_type_name.php

        ā€¢   custom template for the custom post type
Custom Post Types: Displaying
ā€¢   Customizing the custom post type
    template

    ā€¢   single.php

        ā€¢   template for the custom post type (default)

    ā€¢   single-post_type_name.php

        ā€¢   custom template for the custom post type

            ā€¢   eg. single-recipe.php
Custom Post Types: Displaying
Custom Post Types: Displaying
ā€¢   Displaying custom post types on your siteā€™s
    homepage
Custom Post Types: Displaying
ā€¢   Displaying custom post types on your siteā€™s
    homepage

    ā€¢   Add to your themeā€™s functions.php:
Custom Post Types: Displaying
     ā€¢   Displaying custom post types on your siteā€™s
         homepage

         ā€¢   Add to your themeā€™s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );
Custom Post Types: Displaying
     ā€¢   Displaying custom post types on your siteā€™s
         homepage

         ā€¢   Add to your themeā€™s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {
Custom Post Types: Displaying
     ā€¢    Displaying custom post types on your siteā€™s
          homepage

         ā€¢   Add to your themeā€™s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )
Custom Post Types: Displaying
     ā€¢    Displaying custom post types on your siteā€™s
          homepage

         ā€¢   Add to your themeā€™s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )

   
   $query->set( 'post_type', array( 'post', 'recipe' ) );
Custom Post Types: Displaying
     ā€¢    Displaying custom post types on your siteā€™s
          homepage

         ā€¢   Add to your themeā€™s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )

   
   $query->set( 'post_type', array( 'post', 'recipe' ) );


   return $query;
Custom Post Types: Displaying
     ā€¢    Displaying custom post types on your siteā€™s
          homepage

         ā€¢   Add to your themeā€™s functions.php:
add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {


   if ( is_home() )

   
   $query->set( 'post_type', array( 'post', 'recipe' ) );


   return $query;
}
Other Custom Post Type Functions
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
  ā€¢   get_post_type() allows you to check the post type of a
      speciļ¬c post
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);




ā€¢    Check if a post is of a speciļ¬c type:
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);




ā€¢      Check if a post is of a speciļ¬c type:

   ā€¢    is_post_type() allows you to check a speciļ¬c post against
        a speciļ¬c post type
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);




ā€¢      Check if a post is of a speciļ¬c type:

   ā€¢    is_post_type() allows you to check a speciļ¬c post against
        a speciļ¬c post type
if ( is_post_type( 'recipe', $post_id ) )
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);




ā€¢      Check if a post is of a speciļ¬c type:

   ā€¢    is_post_type() allows you to check a speciļ¬c post against
        a speciļ¬c post type
if ( is_post_type( 'recipe', $post_id ) )

   echo 'This is a not a blog post. It is a recipe.';
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);




ā€¢      Check if a post is of a speciļ¬c type:

   ā€¢    is_post_type() allows you to check a speciļ¬c post against
        a speciļ¬c post type
if ( is_post_type( 'recipe', $post_id ) )

   echo 'This is a not a blog post. It is a recipe.';
else
Other Custom Post Type Functions
ā€¢ Get the ā€œpost typeā€ of a post:
    ā€¢    get_post_type() allows you to check the post type of a
         speciļ¬c post
$post_type = get_post_type($post_id);




ā€¢      Check if a post is of a speciļ¬c type:

   ā€¢    is_post_type() allows you to check a speciļ¬c post against
        a speciļ¬c post type
if ( is_post_type( 'recipe', $post_id ) )

   echo 'This is a not a blog post. It is a recipe.';
else

   echo 'This is not a recipe.';
Resources
ā€¢   WordPress.org Codex: register_post_type function reference:

    ā€¢   http://codex.wordpress.org/Function_Reference/register_post_type

ā€¢   Blog post: Custom post types in WordPress:

    ā€¢   http://justintadlock.com/archives/2010/04/29/custom-post-types-in-
        wordpress

ā€¢   Blog post: First impressions of custom post type:

    ā€¢   http://wpengineer.com/impressions-of-custom-post-type/

ā€¢   Plugin: Custom post type UI plugin for WordPress

    ā€¢   http://www.strangework.com/2010/03/03/custom-post-type-ui-plugin-for-
        wordpress/

Mais conteĆŗdo relacionado

Destaque

Workshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learnedWorkshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learnedBas van Dishoeck
Ā 
Custom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealCustom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealJoey Kudish
Ā 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginMainak Goswami
Ā 
Anatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress ThemeAnatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress ThemeJulie Kuehl
Ā 
WordPress Code Architecture
WordPress Code ArchitectureWordPress Code Architecture
WordPress Code ArchitectureMario Peshev
Ā 
WordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress OptimizationWordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress OptimizationJoost de Valk
Ā 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentAizat Faiz
Ā 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialChristos Zigkolis
Ā 

Destaque (9)

Workshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learnedWorkshop 4: IJssel-Vechtdelta lessons learned
Workshop 4: IJssel-Vechtdelta lessons learned
Ā 
Custom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp MontrealCustom Post Types in Depth at WordCamp Montreal
Custom Post Types in Depth at WordCamp Montreal
Ā 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
Ā 
Anatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress ThemeAnatomy and Architecture of a WordPress Theme
Anatomy and Architecture of a WordPress Theme
Ā 
Architecture for WordPress on AWS
Architecture for WordPress on AWSArchitecture for WordPress on AWS
Architecture for WordPress on AWS
Ā 
WordPress Code Architecture
WordPress Code ArchitectureWordPress Code Architecture
WordPress Code Architecture
Ā 
WordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress OptimizationWordCamp Ireland - 40 tips for WordPress Optimization
WordCamp Ireland - 40 tips for WordPress Optimization
Ā 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin Development
Ā 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
Ā 

Semelhante a WordPress 3 Custom Post Types

WP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesWP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesJoe Querin
Ā 
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom FieldsWordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom FieldsJoe Querin
Ā 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post TypesK.Adam White
Ā 
WordPress custom posts types for structured content
WordPress custom posts types for structured contentWordPress custom posts types for structured content
WordPress custom posts types for structured contentFirestorm Creative Studios
Ā 
The 3Cs of WordPress
The 3Cs of WordPressThe 3Cs of WordPress
The 3Cs of WordPressDavid Tufts
Ā 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post TypesMark Jaquith
Ā 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012Stephanie Leary
Ā 
WordPress can do that?!
WordPress can do that?!WordPress can do that?!
WordPress can do that?!Scott McNulty
Ā 
Dev Theming
Dev ThemingDev Theming
Dev Themingbeedragon
Ā 
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...Evan Mullins
Ā 
Using Custom Post Types and Advanced Custom Fields with Elementor
 Using Custom Post Types and Advanced Custom Fields with Elementor Using Custom Post Types and Advanced Custom Fields with Elementor
Using Custom Post Types and Advanced Custom Fields with ElementorAngela Bowman
Ā 
Wordpress Custom Post Types
Wordpress Custom Post TypesWordpress Custom Post Types
Wordpress Custom Post TypesBrent Williams
Ā 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post TypesNile Flores
Ā 
Open Source CMS Playroom
Open Source CMS PlayroomOpen Source CMS Playroom
Open Source CMS Playroomlibrarywebchic
Ā 
Wordpress custom-posttype
Wordpress custom-posttypeWordpress custom-posttype
Wordpress custom-posttypeNaeem Junejo
Ā 
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody HelgesonWordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody HelgesonCody Helgeson
Ā 
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 metadataNicholas Batik
Ā 
How to get your theme in WordPress
How to get your theme in WordPressHow to get your theme in WordPress
How to get your theme in WordPressNisha Singh
Ā 

Semelhante a WordPress 3 Custom Post Types (20)

WP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post TypesWP 101 - Custom Fields & Post Types
WP 101 - Custom Fields & Post Types
Ā 
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom FieldsWordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
WordCamp Kent 2019 - WP 101: Custom Post Type & Custom Fields
Ā 
Stepping Into Custom Post Types
Stepping Into Custom Post TypesStepping Into Custom Post Types
Stepping Into Custom Post Types
Ā 
WordPress custom posts types for structured content
WordPress custom posts types for structured contentWordPress custom posts types for structured content
WordPress custom posts types for structured content
Ā 
The 3Cs of WordPress
The 3Cs of WordPressThe 3Cs of WordPress
The 3Cs of WordPress
Ā 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
Ā 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
Ā 
WordPress can do that?!
WordPress can do that?!WordPress can do that?!
WordPress can do that?!
Ā 
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
Ā 
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...
Ā 
Using Custom Post Types and Advanced Custom Fields with Elementor
 Using Custom Post Types and Advanced Custom Fields with Elementor Using Custom Post Types and Advanced Custom Fields with Elementor
Using Custom Post Types and Advanced Custom Fields with Elementor
Ā 
Wordpress Custom Post Types
Wordpress Custom Post TypesWordpress Custom Post Types
Wordpress Custom Post Types
Ā 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
Ā 
Open Source CMS Playroom
Open Source CMS PlayroomOpen Source CMS Playroom
Open Source CMS Playroom
Ā 
TypeScript
TypeScriptTypeScript
TypeScript
Ā 
Wordpress custom-posttype
Wordpress custom-posttypeWordpress custom-posttype
Wordpress custom-posttype
Ā 
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody HelgesonWordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Wordcamp Phoenix 2012 - Custom Post Types: Now What? By Cody Helgeson
Ā 
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
Ā 
How to get your theme in WordPress
How to get your theme in WordPressHow to get your theme in WordPress
How to get your theme in WordPress
Ā 

ƚltimo

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
Ā 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
Ā 
"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 ...Zilliz
Ā 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vƔzquez
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
Ā 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
Ā 
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...Martijn de Jong
Ā 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
Ā 
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 2024Victor Rentea
Ā 
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...Zilliz
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
Ā 
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, Adobeapidays
Ā 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
Ā 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
Ā 
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 FresherRemote DBA Services
Ā 
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 FMESafe Software
Ā 

ƚltimo (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Ā 
"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 ...
Ā 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
+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...
Ā 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Ā 
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...
Ā 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Ā 
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
Ā 
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...
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Ā 
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
Ā 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
Ā 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
Ā 
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
Ā 
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
Ā 

WordPress 3 Custom Post Types

  • 1. Custom Post types in WordPress 3 Dave Zille May 15, 2010 - WordCamp Victoria BC
  • 2. About Dave ā€¢ President, dazil Internet Services ā€¢ WordPress dev, WordPress conversions ā€¢ web: dazil.com twitter: @dazil ā€¢ Principal, Learn it Today ā€¢ WordPress classroom and online training ā€¢ web: learnittoday.ca twitter: @learnittodayca
  • 3. Agenda ā€¢ Custom Post Types: ā€¢ What are they? What arenā€™t they? ā€¢ Why do we need them? ā€¢ Custom Post Type ideas/examples ā€¢ Demo: ā€¢ Creating a custom post type ā€¢ Displaying a custom post type ā€¢ Resources
  • 4. WordPress 3: Not just for Blogs Anymore! The term ā€œblogā€ has been replaced with ā€œsiteā€ throughout WordPress 3 is (ofļ¬cially) an actual CMS! WordPress install process now asks for ā€œSite Titleā€
  • 5. Top 5 Reasons WP is a CMS:
  • 6. Top 5 Reasons WP is a CMS: 1. Scalability
  • 7. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security
  • 8. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management
  • 9. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management 4. Custom Taxonomies
  • 10. Top 5 Reasons WP is a CMS: 1. Scalability 2. Security 3. Menu Management 4. Custom Taxonomies 5. Custom Post Types
  • 11. What are Custom Post Types? ā€¢ Custom Post Types are ā€œcontentā€ types ā€¢ Not to be confused with ā€œblog postā€ ā€¢ Traditional ā€œpostā€ is actually just another Custom Post Type ā€¢ Can be used to store and administer different types of content on your WordPress site ā€¢ Traditionally done via plugins (Flutter, Pods, etc) ā€¢ A huge part of why WP 3 is a CMS
  • 12. What arenā€™t Custom Post Types? ā€¢ Custom Post Types are not: ā€¢ A replacement for Custom Fields ā€¢ (used in conjunction with Custom Fields) ā€¢ Completely GUI driven ā€¢ (i.e. cannot be created with default WP GUI)
  • 13. Why do we need Custom Post Types? ā€¢ Because Custom Post Types: ā€¢ Make it easy to create and edit different forms of content within WordPress ā€¢ Eliminate the need to ā€œfakeā€ custom post types by using 3rd party plugins ā€¢ Will make you and your clients happy!
  • 14. Custom Post Type Examples ā€¢ Media: ā€¢ Video, Podcasts ā€¢ Title,YouTube URL, Length/Duration, Captions, Show Notes, etc ā€¢ Information: ā€¢ Car for Sale ā€¢ Make, Model, Color, Features, Pictures, etc..
  • 15. Custom Post Type Examples ā€¢ Information (contā€™d) ā€¢ Real Estate Listing ā€¢ Price, # bed, # bath, amenities, photos, etc. ā€¢ Gallery/Portfolio ā€¢ Thumbnail, description, URL, etc. ā€¢ Calendar of Events ā€¢ Date, time, cost, location, etc.
  • 16. Your First Custom Post Type
  • 17. Your First Custom Post Type ā€¢ Case Study:
  • 18. Your First Custom Post Type ā€¢ Case Study: ā€¢ Recipe database
  • 19. Your First Custom Post Type ā€¢ Case Study: ā€¢ Recipe database ā€¢ Description
  • 20. Your First Custom Post Type ā€¢ Case Study: ā€¢ Recipe database ā€¢ Description ā€¢ Ingredients
  • 21. Your First Custom Post Type ā€¢ Case Study: ā€¢ Recipe database ā€¢ Description ā€¢ Ingredients ā€¢ Prep Time
  • 22. Your First Custom Post Type ā€¢ Case Study: ā€¢ Recipe database ā€¢ Description ā€¢ Ingredients ā€¢ Prep Time ā€¢ Cook Time
  • 23. Custom Post Types: The Code ā€¢ The register_post_type() function was introduced in WordPress 2.9 ā€¢ WordPress 3 makes register_post_type() very useful ā€¢ Minimal code, and a Custom Post Type is up and running: add_action( 'init', 'create_recipe_post_type' ); function create_recipe_post_type() { register_post_type( 'recipe', array( 'label' => __( 'Recipes' ), 'singular_label' => __( 'Recipe' ), 'public' => true, ) ); }
  • 24. Custom Post Types: The Code
  • 25. Custom Post Types: The Code ā€¢ Where does the code go? ā€¢ 2 options: ā€¢ Create a plugin ļ¬le, or ā€¢ add to your themeā€™s functions.php
  • 26. Custom Post Types: The Code ā€¢ Where does the code go? ā€¢ 2 options: ā€¢ Create a plugin ļ¬le, or ā€¢ add to your themeā€™s functions.php ā€¢ This is useful, but can I do more? ā€¢ The register_post_type() function has 20+ arguments ā€¢ Can control a lot about CP Types using them ā€¢ Letā€™s review some of them..
  • 27. Custom Post Types: The Code
  • 28. Custom Post Types: The Code register_post_type() arguments ā€¢ label ā€¢ A plural descriptive name for the post type ā€¢ eg ā€œRecipesā€ ā€¢ singular_label ā€¢ A singular descriptive name for the post type ā€¢ eg ā€œRecipeā€
  • 29. Custom Post Types: The Code
  • 30. Custom Post Types: The Code register_post_type() arguments ā€¢ description ā€¢ A short descriptive summary of what the post type is ā€¢ eg. ā€œA set of directions with a list of ingredients for making or preparing food.ā€ ā€¢ public ā€¢ Whether or not the post type should be made available in the admin ā€¢ boolean, default: false
  • 31. Custom Post Types: The Code
  • 32. Custom Post Types: The Code register_post_type() arguments ā€¢ menu_position ā€¢ Allows the positioning of the post type in the admin menu ā€¢ Default: a new post type is added after Comments ā€¢ menu_icon ā€¢ Allows you to specify a custom icon for the post type ā€¢ Default: posts icon
  • 33. Custom Post Types: The Code
  • 34. Custom Post Types: The Code register_post_type() arguments
  • 35. Custom Post Types: The Code register_post_type() arguments ā€¢ hierarchical
  • 36. Custom Post Types: The Code register_post_type() arguments ā€¢ hierarchical ā€¢ Determines whether the post type is hierarchical (as in ā€˜pagesā€™), or not (as in ā€˜postsā€™)
  • 37. Custom Post Types: The Code register_post_type() arguments ā€¢ hierarchical ā€¢ Determines whether the post type is hierarchical (as in ā€˜pagesā€™), or not (as in ā€˜postsā€™) ā€¢ Default: false
  • 38. Custom Post Types: The Code register_post_type() arguments ā€¢ hierarchical ā€¢ Determines whether the post type is hierarchical (as in ā€˜pagesā€™), or not (as in ā€˜postsā€™) ā€¢ Default: false ā€¢ can_export
  • 39. Custom Post Types: The Code register_post_type() arguments ā€¢ hierarchical ā€¢ Determines whether the post type is hierarchical (as in ā€˜pagesā€™), or not (as in ā€˜postsā€™) ā€¢ Default: false ā€¢ can_export ā€¢ Speciļ¬es whether posts of the post type can be exportable using WordPressā€™ export function
  • 40. Custom Post Types: The Code register_post_type() arguments ā€¢ hierarchical ā€¢ Determines whether the post type is hierarchical (as in ā€˜pagesā€™), or not (as in ā€˜postsā€™) ā€¢ Default: false ā€¢ can_export ā€¢ Speciļ¬es whether posts of the post type can be exportable using WordPressā€™ export function ā€¢ Default: true
  • 41. Custom Post Types: The Code
  • 42. Custom Post Types: The Code register_post_type() arguments
  • 43. Custom Post Types: The Code register_post_type() arguments ā€¢ supports
  • 44. Custom Post Types: The Code register_post_type() arguments ā€¢ supports ā€¢ Deļ¬nes what meta boxes and other ļ¬elds appear when editing or creating a post
  • 45. Custom Post Types: The Code register_post_type() arguments ā€¢ supports ā€¢ Deļ¬nes what meta boxes and other ļ¬elds appear when editing or creating a post ā€¢ Options: title, editor, comments, trackbacks, revisions, author, excerpt, thumbnail, custom- ļ¬elds, page-attributes
  • 46. Custom Post Types: The Code register_post_type() arguments ā€¢ supports ā€¢ Deļ¬nes what meta boxes and other ļ¬elds appear when editing or creating a post ā€¢ Options: title, editor, comments, trackbacks, revisions, author, excerpt, thumbnail, custom- ļ¬elds, page-attributes ā€¢ Default: title, editor
  • 47. Custom Post Types: The Code
  • 48. Custom Post Types: The Code register_post_type() arguments
  • 49. Custom Post Types: The Code register_post_type() arguments ā€¢ register_meta_box_cb
  • 50. Custom Post Types: The Code register_post_type() arguments ā€¢ register_meta_box_cb ā€¢ taxonomies
  • 51. Custom Post Types: The Code register_post_type() arguments ā€¢ register_meta_box_cb ā€¢ taxonomies ā€¢ capability_type / capabilities
  • 52. Custom Post Types: Displaying
  • 53. Custom Post Types: Displaying ā€¢ Customizing the custom post type template
  • 54. Custom Post Types: Displaying ā€¢ Customizing the custom post type template ā€¢ single.php
  • 55. Custom Post Types: Displaying ā€¢ Customizing the custom post type template ā€¢ single.php ā€¢ template for the custom post type (default)
  • 56. Custom Post Types: Displaying ā€¢ Customizing the custom post type template ā€¢ single.php ā€¢ template for the custom post type (default) ā€¢ single-post_type_name.php
  • 57. Custom Post Types: Displaying ā€¢ Customizing the custom post type template ā€¢ single.php ā€¢ template for the custom post type (default) ā€¢ single-post_type_name.php ā€¢ custom template for the custom post type
  • 58. Custom Post Types: Displaying ā€¢ Customizing the custom post type template ā€¢ single.php ā€¢ template for the custom post type (default) ā€¢ single-post_type_name.php ā€¢ custom template for the custom post type ā€¢ eg. single-recipe.php
  • 59. Custom Post Types: Displaying
  • 60. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage
  • 61. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php:
  • 62. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' );
  • 63. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) {
  • 64. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() )
  • 65. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) );
  • 66. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) ); return $query;
  • 67. Custom Post Types: Displaying ā€¢ Displaying custom post types on your siteā€™s homepage ā€¢ Add to your themeā€™s functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'recipe' ) ); return $query; }
  • 68. Other Custom Post Type Functions
  • 69. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post:
  • 70. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post
  • 71. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id);
  • 72. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id); ā€¢ Check if a post is of a speciļ¬c type:
  • 73. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id); ā€¢ Check if a post is of a speciļ¬c type: ā€¢ is_post_type() allows you to check a speciļ¬c post against a speciļ¬c post type
  • 74. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id); ā€¢ Check if a post is of a speciļ¬c type: ā€¢ is_post_type() allows you to check a speciļ¬c post against a speciļ¬c post type if ( is_post_type( 'recipe', $post_id ) )
  • 75. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id); ā€¢ Check if a post is of a speciļ¬c type: ā€¢ is_post_type() allows you to check a speciļ¬c post against a speciļ¬c post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.';
  • 76. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id); ā€¢ Check if a post is of a speciļ¬c type: ā€¢ is_post_type() allows you to check a speciļ¬c post against a speciļ¬c post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.'; else
  • 77. Other Custom Post Type Functions ā€¢ Get the ā€œpost typeā€ of a post: ā€¢ get_post_type() allows you to check the post type of a speciļ¬c post $post_type = get_post_type($post_id); ā€¢ Check if a post is of a speciļ¬c type: ā€¢ is_post_type() allows you to check a speciļ¬c post against a speciļ¬c post type if ( is_post_type( 'recipe', $post_id ) ) echo 'This is a not a blog post. It is a recipe.'; else echo 'This is not a recipe.';
  • 78. Resources ā€¢ WordPress.org Codex: register_post_type function reference: ā€¢ http://codex.wordpress.org/Function_Reference/register_post_type ā€¢ Blog post: Custom post types in WordPress: ā€¢ http://justintadlock.com/archives/2010/04/29/custom-post-types-in- wordpress ā€¢ Blog post: First impressions of custom post type: ā€¢ http://wpengineer.com/impressions-of-custom-post-type/ ā€¢ Plugin: Custom post type UI plugin for WordPress ā€¢ http://www.strangework.com/2010/03/03/custom-post-type-ui-plugin-for- wordpress/

Notas do Editor