Skip to content

Instantly share code, notes, and snippets.

@cdils
Created September 27, 2013 21:33
Show Gist options
  • Save cdils/6735486 to your computer and use it in GitHub Desktop.
Save cdils/6735486 to your computer and use it in GitHub Desktop.
Register Portfolio post type and a related taxonomy called Groups
<?php
/**
* This file contains code related to Custom Post Types & Taxonomies
/**
* Create portfolio custom post type
*
*/
function create_post_types() {
// If Portfolio post type is already registered, bail
if ( post_type_exists( 'portfolio' ) )
$return;
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio', 'minimum' ),
'singular_name' => __( 'Portfolio', 'minimum' ),
),
'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/portfolio.png',
'public' => true,
'rewrite' => array( 'slug' => 'portfolio' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo' ),
)
);
}
add_action( 'init', 'create_post_types' );
/**
* Post Type Support for the Genesis Simple Sidebars plugin
*
*/
//add_post_type_support( 'portfolio', 'genesis-simple-sidebars' );
/**
* Create taxonomy `Group` for the `Portfolio` post type
*
*/
function create_taxonomies() {
register_taxonomy( 'group', 'portfolio', array (
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'labels' => array(
'name' => _x( 'Groups', 'taxonomy general name' ),
'singular_name' => _x( 'Group', 'taxonomy singular name' ),
'search_items' => __( 'Search Groups' ),
'all_items' => __( 'All Groups' ),
'parent_item' => __( 'Parent Group' ),
'edit_item' => __( 'Edit Group' ),
'update_item' => __( 'Update Group' ),
'add_new_item' => __( 'Add New Group' ),
'new_item_name' => __( 'New Group Name' ),
'menu_name' => __( 'Groups' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array (
'slug' => 'group', // This controls the base slug that will display before each term
'with_front' => true, // Display the category base before "/group/"
'hierarchical' => true // This will allow URL's like "/group/early-works/painting-name/"
),
));
}
add_action( 'init', 'create_taxonomies' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment