Skip to content

Instantly share code, notes, and snippets.

@nashvillegeek
Created June 10, 2013 19:00
Show Gist options
  • Save nashvillegeek/5751278 to your computer and use it in GitHub Desktop.
Save nashvillegeek/5751278 to your computer and use it in GitHub Desktop.
Sublime Text 2 - Register Custom Post Type for Bones
<snippet>
<content><![CDATA[
// let's create the function for the custom type
function ng_cpt_${1:function_name}() {
// creating (registering) the custom type
register_post_type( 'cpt_${2:custom_type_plural}', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
// let's now add all the options for this post type
array('labels' => array(
'name' => __('${3:custom_type_plural_capital}', 'bonestheme'), /* This is the Title of the Group */
'singular_name' => __('${4:custom_type_singular_capital}', 'bonestheme'), /* This is the individual type */
'all_items' => __('All ${3:custom_type_plural_capital}', 'bonestheme'), /* the all items menu item */
'add_new' => __('Add New', 'bonestheme'), /* The add new menu item */
'add_new_item' => __('Add New ${4:custom_type_singular_capital}', 'bonestheme'), /* Add New Display Title */
'edit' => __( 'Edit', 'bonestheme' ), /* Edit Dialog */
'edit_item' => __('Edit ${4:custom_type_singular_capital}', 'bonestheme'), /* Edit Display Title */
'new_item' => __('New ${4:custom_type_singular_capital}', 'bonestheme'), /* New Display Title */
'view_item' => __('View ${4:custom_type_singular_capital}', 'bonestheme'), /* View Display Title */
'search_items' => __('Search ${3:custom_type_plural_capital}', 'bonestheme'), /* Search Custom Type Title */
'not_found' => __('Nothing found in the Database.', 'bonestheme'), /* This displays if there are no entries yet */
'not_found_in_trash' => __('Nothing found in Trash', 'bonestheme'), /* This displays if there is nothing in the trash */
'parent_item_colon' => ''
), /* end of arrays */
'description' => __( 'This is the ${3:custom_type_plural_capital} custom post type', 'bonestheme' ), /* Custom Type Description */
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_position' => 8, /* this is what order you want it to appear in on the left hand side menu */
'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
'rewrite' => array( 'slug' => '${2:custom_type_plural}', 'with_front' => false ), /* you can specify its url slug */
'has_archive' => '${2:custom_type_plural}', /* you can rename the slug here */
'capability_type' => 'post',
'hierarchical' => false,
/* the next one is important, it tells what's enabled in the post editor */
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
) /* end of options */
); /* end of register post type */
/* this adds your post categories to your custom post type */
//register_taxonomy_for_object_type('category', 'cpt_${2:custom_type_plural}');
/* this adds your post tags to your custom post type */
//register_taxonomy_for_object_type('post_tag', 'cpt_${2:custom_type_plural}');
}
// adding the function to the Wordpress init
add_action( 'init', 'ng_cpt_${1:function_name}');
/*
for more information on taxonomies, go here:
http://codex.wordpress.org/Function_Reference/register_taxonomy
*/
// now let's add custom categories (these act like categories)
register_taxonomy( '${2:custom_type_plural}_cat',
array('cpt_${2:custom_type_plural}'), /* if you change the name of register_post_type( 'cpt_${2:custom_type_plural}', then you have to change this */
array('hierarchical' => true, /* if this is true, it acts like categories */
'labels' => array(
'name' => __( '${4:custom_type_singular_capital} Categories', 'bonestheme' ), /* name of the custom taxonomy */
'singular_name' => __( '${4:custom_type_singular_capital} Category', 'bonestheme' ), /* single taxonomy name */
'search_items' => __( 'Search ${4:custom_type_singular_capital} Categories', 'bonestheme' ), /* search title for taxomony */
'all_items' => __( 'All ${4:custom_type_singular_capital} Categories', 'bonestheme' ), /* all title for taxonomies */
'parent_item' => __( 'Parent ${4:custom_type_singular_capital} Category', 'bonestheme' ), /* parent title for taxonomy */
'parent_item_colon' => __( 'Parent ${4:custom_type_singular_capital} Category:', 'bonestheme' ), /* parent taxonomy title */
'edit_item' => __( 'Edit ${4:custom_type_singular_capital} Category', 'bonestheme' ), /* edit custom taxonomy title */
'update_item' => __( 'Update ${4:custom_type_singular_capital} Category', 'bonestheme' ), /* update title for taxonomy */
'add_new_item' => __( 'Add New ${4:custom_type_singular_capital} Category', 'bonestheme' ), /* add new title for taxonomy */
'new_item_name' => __( 'New ${4:custom_type_singular_capital} Category Name', 'bonestheme' ) /* name title for taxonomy */
),
'show_admin_column' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => '${2:custom_type_plural}' ),
)
);
// now let's add custom tags (these act like categories)
register_taxonomy( '${2:custom_type_plural}_tag',
array('cpt_${2:custom_type_plural}'), /* if you change the name of register_post_type( 'cpt_${2:custom_type_plural}', then you have to change this */
array('hierarchical' => false, /* if this is false, it acts like tags */
'labels' => array(
'name' => __( '${4:custom_type_singular_capital} Tags', 'bonestheme' ), /* name of the custom taxonomy */
'singular_name' => __( '${4:custom_type_singular_capital} Tag', 'bonestheme' ), /* single taxonomy name */
'search_items' => __( 'Search ${4:custom_type_singular_capital} Tags', 'bonestheme' ), /* search title for taxomony */
'all_items' => __( 'All ${4:custom_type_singular_capital} Tags', 'bonestheme' ), /* all title for taxonomies */
'parent_item' => __( 'Parent ${4:custom_type_singular_capital} Tag', 'bonestheme' ), /* parent title for taxonomy */
'parent_item_colon' => __( 'Parent ${4:custom_type_singular_capital} Tag:', 'bonestheme' ), /* parent taxonomy title */
'edit_item' => __( 'Edit ${4:custom_type_singular_capital} Tag', 'bonestheme' ), /* edit custom taxonomy title */
'update_item' => __( 'Update ${4:custom_type_singular_capital} Tag', 'bonestheme' ), /* update title for taxonomy */
'add_new_item' => __( 'Add New ${4:custom_type_singular_capital} Tag', 'bonestheme' ), /* add new title for taxonomy */
'new_item_name' => __( 'New ${4:custom_type_singular_capital} Tag Name', 'bonestheme' ) /* name title for taxonomy */
),
'show_admin_column' => true,
'show_ui' => true,
'query_var' => true,
)
);
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>newcpt</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment