post

Developing a Custom Post Type and a Custom Taxonomy in Genesis with Custom Pages, Part 1

Custom Post Type Metaboxes

Recently, someone contacted me to develop a custom post type setup for their website, and they were lamenting how there is nothing on the web that succinctly walks them through the process: soup to nuts. So here’s my attempt! However, I am going to assume basic knowledge of custom post types. If you haven’t read through my Understanding Custom Post Types series yet, you may want to do that.

First, I created a new php file called wps-admin-functions.php. This is where we will house our Custom Post Types, Taxonomies, and Metaboxes. We could have added this to our theme’s function.php file but this will allow us to have a separate file dedicated to our newly added features. To do this, simply create a new text document in your favorite text editor and save as wps-admin-functions.php.

1. Register your Custom Post Type

[php]<?php
// registration code for discbrakes post type
function wps_register_discbrakes_posttype() {
$labels = array(
‘name’ => _x( ‘Disc Brakes’, ‘post type general name’ ),
‘singular_name’ => _x( ‘Disc Brake’, ‘post type singular name’ ),
‘add_new’ => _x( ‘Add New’, ‘Disc Brake’),
‘add_new_item’ => __( ‘Add New Disc Brake ‘),
‘edit_item’ => __( ‘Edit Disc Brake ‘),
‘new_item’ => __( ‘New Disc Brake ‘),
‘view_item’ => __( ‘View Disc Brake ‘),
‘search_items’ => __( ‘Search Disc Brakes ‘),
‘not_found’ => __( ‘No Disc Brake found’ ),
‘not_found_in_trash’ => __( ‘No Disc Brakes found in Trash’ ),
‘parent_item_colon’ => ”
);

$supports = array( ‘title’ , ‘editor’ , ‘thumbnail’ , ‘excerpt’ , ‘revisions’ );

$post_type_args = array(
‘labels’ => $labels,
‘singular_label’ => __( ‘Disc Brake’ ),
‘public’ => true,
‘show_ui’ => true,
‘publicly_queryable’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘rewrite’ => array( ‘slug’ => ‘discbrakes’ ),
‘supports’ => $supports,
‘menu_position’ => 5,
‘taxonomies’ => array( ‘wps_axlesizes’ ),
‘menu_icon’ => ‘http://mydomain.com/wp-content/themes/lib/images/discbrakes-icon.png’
);
register_post_type( ‘wps_discbrakes’ , $post_type_args );
}
add_action( ‘init’, ‘wps_register_discbrakes_posttype’ );
[/php]

Notice in this code that I associate my custom post type with my coming custom taxonomy: 'taxonomies' => array( 'wps_axlesizes' ),. Also, note that I am using a prefix on both my custom post type and taxonomy. The reason this is done is that there may be a naming conflict with a plugin or other code in your theme. The prefix uniquely identifies it to prevent this. It is a best practice, and make sure you do not use the wp_ or genesis_ prefixes.

2. Register your Custom Taxonomy

[php]<?php
// registration code for AxleSizes taxonomy
function wps_register_axlesizes_tax() {
$labels = array(
‘name’ => _x( ‘Axle Sizes’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Axle Size’, ‘taxonomy singular name’ ),
‘add_new’ => _x( ‘Add New Axle Size’, ‘Axle Size’),
‘add_new_item’ => __( ‘Add New Axle Size’ ),
‘edit_item’ => __( ‘Edit Axle Size’ ),
‘new_item’ => __( ‘New Axle Size’ ),
‘view_item’ => __( ‘View Axle Size’ ),
‘search_items’ => __( ‘Search Axle Sizes’ ),
‘not_found’ => __( ‘No Axle Size found’ ),
‘not_found_in_trash’ => __( ‘No Axle Size found in Trash’ ),
);

$pages = array( ‘wps_discbrakes’ );

$args = array(
‘labels’ => $labels,
‘singular_label’ => __( ‘Axle Size’ ),
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => false,
‘show_tagcloud’ => false,
‘show_in_nav_menus’ => true,
‘rewrite’ => array(‘slug’ => ‘axle-sizes’),
);
register_taxonomy( ‘wps_axlesizes’ , $pages , $args );
}
add_action( ‘init’ , ‘wps_register_axlesizes_tax’ );[/php]

Custom Post TypeNotice in the registration, the taxonomy is associated with my custom post type: $pages = array( 'wps_discbrakes' );.

Once these are registered, you should see your custom post type to the left under POST.

3. Create my Metaboxes
With metaboxes, you can go the long way; however, I prefer to use a class. Soon WordPress will have a metabox class, hopefully in WordPress 3.3, so this section will be rendered “obsolete” yet still usable. First, download the custom metabox code from GitHub. For a great explanation of the code, see Bill Erickson’s tutorial. Because of the tutorial, I won’t break down this section.

Once downloaded, place the metabox folder in your lib folder in the child theme folder so that: CHILD_URL . '/lib/metabox/init.php'

So the file structure is
CHILD-THEME-FOLDER

  • IMAGES FOLDER
  • LIB FOLDER
    • METABOX FOLDER
    • IMAGES FOLDER
    • wps-admin-functions.php
  • functions.php
  • style.css
  • readme.txt

[php]<?php
// Create Metaboxes
$prefix = ‘_wps_’;
add_filter( ‘cmb_meta_boxes’, ‘wps_create_metaboxes’ );
function wps_create_metaboxes() {
global $prefix;

$meta_boxes[] = array(
‘id’ => ‘disk-brakes-info’,
‘title’ => ‘Disk Brakes Information’,
‘pages’ => array( ‘wps_discbrakes’ ), // post type
‘context’ => ‘normal’,
‘priority’ => ‘low’,
‘show_names’ => true, // Show field names left of input
‘fields’ => array(
array(
‘name’ => ‘Instructions’,
‘desc’ => ‘In the right column upload a featured image. Make sure this image is at least 900x360px wide. Then fill out the information below.’,
‘id’ => $prefix . ‘title’,
‘type’ => ‘title’,
),
array(
‘name’ => ‘Part Number’,
‘desc’ => ‘Enter the part number (e.g., XXXXXXX)’,
‘id’ => $prefix . ‘part_number’,
‘type’ => ‘text’
),
array(
‘name’ => ‘Rotor’,
‘desc’ => ”,
‘id’ => $prefix . ‘rotor’,
‘type’ => ‘select’,
‘options’ => array(
array(‘name’ => ‘Stainless Steel’, ‘value’ => ‘stainless-steel’),
array(‘name’ => ‘E-Coat (Black)’, ‘value’ => ‘e-coat-black’),
array(‘name’ => ‘Option Three’, ‘value’ => ‘none’)
)
),
array(
‘name’ => ‘Caliper’,
‘desc’ => ”,
‘id’ => $prefix . ‘caliper’,
‘type’ => ‘select’,
‘options’ => array(
array(‘name’ => ‘Stainless Steel’, ‘value’ => ‘stainless-steel’),
array(‘name’ => ‘E-Coat (Black)’, ‘value’ => ‘e-coat-black’),
array(‘name’ => ‘Option Three’, ‘value’ => ‘none’)
)
),
array(
‘name’ => ‘Mounting Bracket’,
‘desc’ => ”,
‘id’ => $prefix . ‘mounting_bracket’,
‘type’ => ‘select’,
‘options’ => array(
array(‘name’ => ‘Stainless Steel’, ‘value’ => ‘stainless-steel’),
array(‘name’ => ‘E-Coat (Black)’, ‘value’ => ‘e-coat-black’),
array(‘name’ => ‘Option Three’, ‘value’ => ‘none’)
)
),
array(
‘name’ => ‘Weight per Axle Set’,
‘desc’ => ‘e.g., 45 LBS.’,
‘id’ => $prefix . ‘weight_per_axle_set’,
‘type’ => ‘text’
),
),
);

return $meta_boxes;
}

// Initialize the metabox class
add_action( ‘init’, ‘be_initialize_cmb_meta_boxes’, 9999 );
function be_initialize_cmb_meta_boxes() {
if ( !class_exists( ‘cmb_Meta_Box’ ) ) {
require_once(CHILD_DIR . ‘/lib/metabox/init.php’);
}
}
[/php]

This will create the metaboxes for the custom post type.
Custom Post Type Metaboxes

4. Clear Permalinks
Now in your admin area, navigate to Settings > Permalinks and click Save Changes. This will flush and clear your permalinks. This is important if you are getting strange 404 Page Not Found errors.

So our finished product is this: wps-admin-functions.php

[php]
<?php

/**
* Admin Functions
*
* This file is responsible for registering the
* custom post types, taxonomies, and metaboxes.
*
* @author Travis Smith <travis@wpsmith.net>
* @copyright Copyright (c) 2011, Travis Smith
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/

// registration code for discbrakes post type
// registration code for discbrakes post type
function wps_register_discbrakes_posttype() {
$labels = array(
‘name’ => _x( ‘Disc Brakes’, ‘post type general name’ ),
‘singular_name’ => _x( ‘Disc Brake’, ‘post type singular name’ ),
‘add_new’ => _x( ‘Add New’, ‘Disc Brake’),
‘add_new_item’ => __( ‘Add New Disc Brake ‘),
‘edit_item’ => __( ‘Edit Disc Brake ‘),
‘new_item’ => __( ‘New Disc Brake ‘),
‘view_item’ => __( ‘View Disc Brake ‘),
‘search_items’ => __( ‘Search Disc Brakes ‘),
‘not_found’ => __( ‘No Disc Brake found’ ),
‘not_found_in_trash’ => __( ‘No Disc Brakes found in Trash’ ),
‘parent_item_colon’ => ”
);

$supports = array( ‘title’ , ‘editor’ , ‘thumbnail’ , ‘excerpt’ , ‘revisions’ );

$post_type_args = array(
‘labels’ => $labels,
‘singular_label’ => __( ‘Disc Brake’ ),
‘public’ => true,
‘show_ui’ => true,
‘publicly_queryable’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘rewrite’ => array( ‘slug’ => ‘discbrakes’ ),
‘supports’ => $supports,
‘menu_position’ => 5,
‘taxonomies’ => array( ‘wps_axlesizes’ ),
‘menu_icon’ => ‘http://mydomain.com/wp-content/themes/lib/images/discbrakes-icon.png’
);
register_post_type( ‘wps_discbrakes’ , $post_type_args );
}
add_action( ‘init’, ‘wps_register_discbrakes_posttype’ );

// registration code for AxleSizes taxonomy
function wps_register_axlesizes_tax() {
$labels = array(
‘name’ => _x( ‘Axle Sizes’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Axle Size’, ‘taxonomy singular name’ ),
‘add_new’ => _x( ‘Add New Axle Size’, ‘Axle Size’),
‘add_new_item’ => __( ‘Add New Axle Size’ ),
‘edit_item’ => __( ‘Edit Axle Size’ ),
‘new_item’ => __( ‘New Axle Size’ ),
‘view_item’ => __( ‘View Axle Size’ ),
‘search_items’ => __( ‘Search Axle Sizes’ ),
‘not_found’ => __( ‘No Axle Size found’ ),
‘not_found_in_trash’ => __( ‘No Axle Size found in Trash’ ),
);

$pages = array( ‘wps_discbrakes’ );

$args = array(
‘labels’ => $labels,
‘singular_label’ => __( ‘Axle Size’ ),
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => false,
‘show_tagcloud’ => false,
‘show_in_nav_menus’ => true,
‘rewrite’ => array(‘slug’ => ‘axle-sizes’),
);
register_taxonomy( ‘wps_axlesizes’ , $pages , $args );
}
add_action( ‘init’ , ‘wps_register_axlesizes_tax’ );

// Create Metaboxes
$prefix = ‘_wps_’;
add_filter( ‘cmb_meta_boxes’, ‘wps_create_metaboxes’ );
function wps_create_metaboxes() {
global $prefix;

$meta_boxes[] = array(
‘id’ => ‘disk-brakes-info’,
‘title’ => ‘Disk Brakes Information’,
‘pages’ => array( ‘wps_discbrakes’ ), // post type
‘context’ => ‘normal’,
‘priority’ => ‘low’,
‘show_names’ => true, // Show field names left of input
‘fields’ => array(
array(
‘name’ => ‘Instructions’,
‘desc’ => ‘In the right column upload a featured image. Make sure this image is at least 900x360px wide. Then fill out the information below.’,
‘id’ => $prefix . ‘title’,
‘type’ => ‘title’,
),
array(
‘name’ => ‘Part Number’,
‘desc’ => ‘Enter the part number (e.g., XXXXXXX)’,
‘id’ => $prefix . ‘part_number’,
‘type’ => ‘text’
),
array(
‘name’ => ‘Rotor’,
‘desc’ => ”,
‘id’ => $prefix . ‘rotor’,
‘type’ => ‘select’,
‘options’ => array(
array(‘name’ => ‘Stainless Steel’, ‘value’ => ‘stainless-steel’),
array(‘name’ => ‘E-Coat (Black)’, ‘value’ => ‘e-coat-black’),
array(‘name’ => ‘Option Three’, ‘value’ => ‘none’)
)
),
array(
‘name’ => ‘Caliper’,
‘desc’ => ”,
‘id’ => $prefix . ‘caliper’,
‘type’ => ‘select’,
‘options’ => array(
array(‘name’ => ‘Stainless Steel’, ‘value’ => ‘stainless-steel’),
array(‘name’ => ‘E-Coat (Black)’, ‘value’ => ‘e-coat-black’),
array(‘name’ => ‘Option Three’, ‘value’ => ‘none’)
)
),
array(
‘name’ => ‘Mounting Bracket’,
‘desc’ => ”,
‘id’ => $prefix . ‘mounting_bracket’,
‘type’ => ‘select’,
‘options’ => array(
array(‘name’ => ‘Stainless Steel’, ‘value’ => ‘stainless-steel’),
array(‘name’ => ‘E-Coat (Black)’, ‘value’ => ‘e-coat-black’),
array(‘name’ => ‘Option Three’, ‘value’ => ‘none’)
)
),
array(
‘name’ => ‘Weight per Axle Set’,
‘desc’ => ‘e.g., 45 LBS.’,
‘id’ => $prefix . ‘weight_per_axle_set’,
‘type’ => ‘text’
),
),
);

return $meta_boxes;
}

// Initialize the metabox class
add_action( ‘init’, ‘wps_initialize_cmb_meta_boxes’, 9999 );
function wps_initialize_cmb_meta_boxes() {
if ( !class_exists( ‘cmb_Meta_Box’ ) ) {
require_once(CHILD_DIR . ‘/lib/metabox/init.php’);
}
}
[/php]

post

Custom Post Types and Using Meta Boxes

Custom Post Types and Custom Metaboxes

Understanding WordPress Custom Post Types

First, if there is any confusion, WordPress refers to metaboxes as one word (see add_meta_box and remove_meta_box). The confusion rises because of the function name which separates the words. While I am not going to speculate as to the right way, as far as I am concerned, it doesn’t matter. But that may be because I don’t have a dog in the fight or discussion. So I will defer to better and smarter people. These same zealots are the ones who argue for the proper spelling of WordPress not extending grace at times, even when a person who knows better may mistakenly type something different. Again, to me, while spelling WordPress correctly matters from a branding perspective, from a developer’s perspective where everything is lower case or camel case, again it doesn’t matter (esp since all WordPress functions abbreviate WordPress to wp_). Now on to more pressing things (function off_soap_box() {break;}).

There are several posts on how to incorporate custom fields and metaboxes into your custom post type. To me this is the most difficult part of custom post types. You can also find a plethora of examples and tutorials of custom metaboxes for your custom post type that use simple text fields or text areas (e.g., a good video metabox example by Andrew Dodson, a good example here by function, new2wp for a simple metabox for links & link descriptions, Re-cycled Air, .net Magazine for Tumblr-like metabox for quotes with post formats), as those are the most popular. However, finding good tutorials on the use of checkboxes or radio buttons are a bit more difficult to find. Jeremiah Tolbert gives a good tutorial on a dropdown selection metabox.

Two notable examples are Curtis Henson’s Links custom post type using a PHP Class and WPTheming’s Events metaboxes, good thorough tutorial.

However, I need to clarify something that I hear a lot. When you register your custom post type, you have the opportunity to use an argument called “register_meta_box_cb.” However, you do not have to use that argument. Using it allows you to cut a couple steps, but if you are using free custom post type plugins then they probably do not offer this ability.

To add a metabox to a custom post type,
[php]<?php
// Add the Metabox for CPT

add_action( ‘add_meta_boxes’, ‘add_cpt_metabox’, 10 ); //note, it has to be add_meta_boxes hook for WP 3.0+
function add_cpt_metabox() {
add_meta_box(‘cpt-metabox’, ‘Metabox TITLE’, ‘prefix_cpt_metabox_function’, ‘my_cpt_registered_name’, ‘normal’, ‘default’);
}

// The CPT Metabox
function prefix_cpt_metabox_function() {
// Noncename needed to verify where the data originated
echo ‘<input type="hidden" name="cpt_metabox_noncename" id="cpt_metabox_noncename" value="’ . wp_create_nonce( plugin_basename(__FILE__) ) . ‘" />’;

// Echo metabox body stuff (fields/text, etc)
}

/* Do something with the data entered */
add_action( ‘save_post’, ‘prefix_cpt_metabox_save_postdata’ );
function prefix_cpt_metabox_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE )
return;

// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times

if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )
return;

// Check permissions
if ( ‘page’ == $_POST['post_type'] )
{
if ( !current_user_can( ‘edit_page’, $post_id ) )
return;
}
else
{
if ( !current_user_can( ‘edit_post’, $post_id ) )
return;
}

// OK, we’re authenticated: we need to find and save the data

$mydata = $_POST['myplugin_new_field'];

// Do something with $mydata
// probably using add_post_meta(), update_post_meta(), or
// a custom table (see Further Reading section below)

return $mydata;
}
[/php]

For a good alternative for saving, see Nathan Rice’s code: Adapted version presented by WP Theming’s Post, How to Add a Metabox to a Custom Post Type.

These examples provide good hard coding examples, so I wanted to discuss two other possibilities.
First is a plugin: More Fields, which works perfectly with More Types and More Taxonomies.

Custom Post Types and Custom Metaboxes

Click for Larger Image


Second and a much better choice in my option as it is extremely flexible is the Custom Metaboxes and Fields for WordPress script by Andrew Norcross (@norcross), Jared Atchison (@jaredatch), and Bill Erickson (@billerickson). Bill Erickson has written a brief example here with an excellent subsequent discussion in the comments area.

However, here is an example that I have used recently with a restaurant theme and a menu item post type.

Here’s how to set up your own metaboxes:

  1. Download a copy of our metabox code from GitHub
  2. Create a “lib” directory in your theme or child theme, and a “metabox” directory inside “lib”. Upload the files you downloaded above into /wp-content/themes/your-theme/lib/metabox
  3. Include ‘/lib/metabox/init.php’ in your functions.php file, and define your metaboxes in an array (see below). For Genesis users, it’s require_once( CHILD_DIR . ‘/lib/metabox/init.php’ );; for others, try require_once( STYLESHEETPATH . ‘/lib/metabox/init.php’ );

Each metabox is stored as an array. There’s a ton of field options, including text, textarea, checkbox, dropdown list, and WYSIWYG. For examples on how to use all the fields, look at /metabox/example-functions.php.

First step is that I registered my custom post type.

[php]<?php add_action(‘init’, ‘dp_cpt_init’);
function dp_cpt_init() {
$labels= array( ‘name’ =–> _x(‘Menu Items’, ‘post type general name’),
‘singular_name’ => _x(‘Menu Item’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘menu_item’),
‘add_new_item’ => __(‘Add New Menu Item’),
‘edit_item’ => __(‘Edit Menu Item’),
‘new_item’ => __(‘New Menu Item’),
‘view_item’ => __(‘View Menu Item’),
‘search_items’ => __(‘Search Menu Item’),
‘not_found’ => __(‘No menu items found’),
‘not_found_in_trash’ => __(‘No menu items found in Trash’),
‘parent_item_colon’ => ”,
‘menu_name’ => ‘Menu Items’
);

$args = array(
‘labels’ => $labels,
‘description’ => ‘Menu items for various menus.’,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’ => ‘menu-item’),
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ => null,
‘menu_icon’ => CHILD_URL .’/lib/cpt/images/menu_item_cpt_16x16.png’,
‘supports’ => array(‘title’,’editor’,’revisions’,’thumbnail’),
‘taxonomies’ => array(‘dp_menu’,’dp_toppings’)
);
register_post_type( ‘dp_menu_items’ , $args );

}

add_action( ‘init’, ‘dp_create_custom_taxonomies’, 0 );
function dp_create_custom_taxonomies() {
//Register Taxonomies
register_taxonomy(‘dp_menu’,array (0 => ‘dp_menu_items’),array( ‘hierarchical’ => true, ‘label’ => ‘Menus’,’show_ui’ => true,’query_var’ => true,’rewrite’ => array(‘slug’ => ‘menus’),’singular_label’ => ‘Menu’) );
register_taxonomy(‘dp_toppings’,array (0 => ‘dp_menu_items’),array( ‘hierarchical’ => false, ‘label’ => ‘Toppings’,’show_ui’ => true,’query_var’ => true,’rewrite’ => array(‘slug’ => ‘toppings’),’singular_label’ => ‘Topping’) );
}
[/php]

Second step is to follow Bill’s steps, and add the following below the previous content.

[php]require_once( CHILD_DIR . ‘/lib/metabox/init.php’ );
// Include & setup custom metabox and fields
$prefix = ‘dp_’;
$meta_boxes = array();
global $price_info;

$meta_boxes[] = array(
‘id’ => ‘dp_menu_item_info’,
‘title’ => ‘Menu Item Price Information’,
‘pages’ => array(‘dp_menu_items’), // post type
‘context’ => ‘side’,
‘priority’ => ‘high’,
‘show_names’ => true, // Show field names on the left
‘fields’ => array(
array(
‘name’ => ‘Small Pizza Price’,
‘desc’ => ‘Small Pizza’,
‘id’ => $prefix . ‘price_textmoney’, // dp_price_textmoney
‘type’ => ‘text_money’
),
array(
‘name’ => ‘Medium Pizza Price’,
‘desc’ => ‘Medium Pizza’,
‘id’ => $prefix . ‘price1_textmoney’, // dp_price1_textmoney
‘type’ => ‘text_money’
),
array(
‘name’ => ‘Large Pizza Price’,
‘desc’ => ‘Large Pizza’,
‘id’ => $prefix . ‘price2_textmoney’, // dp_price2_textmoney
‘type’ => ‘text_money’
),
array(
‘name’ => ‘Extra Large Pizza Price’,
‘desc’ => ‘XL Pizza’,
‘id’ => $prefix . ‘price3_textmoney’, // dp_price3_textmoney
‘type’ => ‘text_money’
),
array(
‘name’ => ‘Sale Price’,
‘desc’ => ‘Sale Campaign Price’,
‘id’ => $prefix . ‘price4_textmoney’, // dp_price4_textmoney
‘type’ => ‘text_money’
)
)
);
[/php]
And here is an example of the outcome:
Custom Post Type metabox Example

post

Custom Post Types, Post Formats, Custom Taxonomies, and Custom Fields and Meta Boxes

Understanding WordPress Custom Post Types
This is the new WordPress Soup: Custom Post Types, Post Formats, Custom Taxonomies, and Custom Fields/Meta Boxes. First and foremost, since we have already talked about what custom post types are, let’s define the other two: post formats and custom taxonomies.

Post Formats

Tapestry Theme - A Tumblog-Style Theme for WordPress using Post FormatsPost formats are not post types, that is, they are not content types. Instead, they are varying types of posts. They are posts with varying formatting. For example, consider the following:

  • a shared link should have a link as its focus.
  • a video should have a video as its focus, maybe its only content
  • an image should have an image as its focus, maybe again, its only content
  • a quote should have a quote as its focus, maybe its only content
  • Etc.

As Mark Jaquith states:

A Post Format is a formatting designation made to a post. For example, a post could be a short “aside,” or a Kottke.org-style link post, or a video post, or a photo gallery post. The data you input might be slightly different — video post should contain a video, an aside should probably not be very long, a link post should have a link. And the way that the post is displayed on the site might be very different — an aside will typically be displayed without a title, a link post may have the title point to the link. A video post may be wider, or have social sharing buttons auto-appended. But they’re all still posts. They still show up in your feed, and you still find them in the Posts section of the WordPress backend.

There are two major differences between custom post types and post formats. They are:

  1. Post formats will appear in the main RSS. Custom post types do not appear in the RSS feed by default without further coding (though in my opinion this should be part of the registration coding as it is with searching).
  2. Post formats are a WordPress “standardized convention.” In other words, instead of using categories to customize output and display (that may or may not be supported across themes/frameworks), post formats provides a standard method of doing this.

Simply, think Tumblr! StudioPress’s Tapestry Child Theme makes good use of Post Formats.

As far as WordPress is concerned, there are ONLY 10 Post Formats available to users/theme developers. They are:

  1. standard – regular post
  2. aside – Typically styled without a title. Similar to a Facebook note update.
  3. gallery – A gallery of images. Post will likely contain a gallery shortcode and will have image attachments.
  4. link – A link to another site.
  5. image – A single image.
  6. quote – A quotation. Probably will contain a blockquote holding the quote content. Alternatively, the quote may be just the content, with the source/author being the title.
  7. status – A short status update, similar to a Twitter status update.
  8. video – A single video.
  9. audio – An audio file. Could be used for Podcasting.
  10. chat – A chat transcript

Now, just like thumbnail images, post formats must be activated by the theme.

[php]add_theme_support( ‘post-formats’ , array( ‘aside’ , ‘chat’ , ‘gallery’ , ‘image’ , ‘link’ , ‘quote’ , ‘status’ , ‘video’ , ‘audio’ ) );[/php]

To style post formats, use the following new CSS classes:

Standard: Normal CSS
Aside: .format-aside {}
Audio: .format-audio {}
Chat: .format-chat {}
Gallery: .format-gallery {}
Image: .format-image {}
Link: .format-link {}
Quote: .format-quote {}
Status: .format-status {}
Video: .format-video {}

Custom Taxonomies

Think Categories and Tags. These both represent two types of taxonomies: hierarchical, where terms can have a parent-child relationship (e.g.,categories) and non-hierarchical, where all terms are equal (e.g., tags). Custom taxonomies give you the ability to name and create taxonomies that act like Tags and Categories but are named whatever you’d like to name them.

Other built-in taxonomies include Link Category and Nav Menu. So what are some custom taxonomies? These can be determined by custom post types and can be whatever you need them to be; for example, an employee custom post type could use an employee departments hierarchical taxonomy. Another example could be a movie custom post type utilizing multiple taxonomies of genre, director, stars/actors, etc. (More information forthcoming…)

Custom Fields and Meta Boxes

These are designated areas to input information on a per post/custom post (or content entry) basis. Generally speaking, if the Title, Editor, etc. that is found on a post won’t do what you want it to do with the content, then most people add custom fields that creates an easy way to input content as well as display the content. Custom Meta Boxes and Custom Fields are sets of additional editable fields that may be added to any post type, whether page, post, or a custom post type. The custom fields can be used to store any sort of content/data that you want. They are often single line input boxes, checkboxes, dropdown boxes, paragraph text areas, radio buttons, etc. There will be more on this later as Custom Meta Boxes and Custom Fields are usually extremely important to Custom Post Types. (More information forthcoming…)

Summary

So, in short, custom post types are content types for custom storing with custom displays on the backend and front end. Post formats are types or variations of displaying content on the front end only coming with a standardize set of 10 choices. Custom taxonomies are terms, whether hierarchical or not, that are used for organizing content. Custom Meta Boxes and Fields are designated areas to add more information beyond the standard title, editor, etc. (which are displayed via built-in meta boxes).

More Information/Further Reading

Post Formats Links

Custom Taxonomies Links

Other

post

Permenantly Fix Genesis’s Admin Metabox Widths

genesis-metaboxes_800.png

In the StudioPress Support Forum, Charles Clarkson helped me with a problem that I’ve had for some time now. I have wanted StudioPress to change their .genesis-metaboxes .metabox-holder from its default of 800px to auto on the Theme Settings under Genesis tab (http://yourdomain.com/wp-admin/admin.php?page=genesis).

Genesis Default (800px): Click Image for Larger Image

However, after every upgrade I had to edit the admin.css to make this happen.

My Preference (auto): Click Image for Larger Image

So finally I posted this in the forums and Charles gave me the following code to free me from remembering to do that. And here it is:

[php]
add_action( ‘admin_footer’, ‘child_widen_theme_settings’ );
function child_widen_theme_settings() { ?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
$( '.genesis-metaboxes, .genesis-metaboxes .metabox-holder' ).css( 'width', 'auto' );
//]]>
});
</script>
<?php
} [/php]