Skip to content

Instantly share code, notes, and snippets.

@jasonabney
Created May 27, 2015 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonabney/0fe2d314937d3c10f976 to your computer and use it in GitHub Desktop.
Save jasonabney/0fe2d314937d3c10f976 to your computer and use it in GitHub Desktop.
Kellen Clients Custom Post Type & Taxonomy
/**
* Return Archive Section
* @author Bill Erickson
* @link http://www.billerickson.net/code/helper-function-for-template-include-and-body-class/
*
* @param null
* @return string
*/
function be_return_archive_section() {
if( is_post_type_archive( 'kellen_clients' ) || is_tax( 'client_category' ) )
return 'kellen_clients';
if( is_post_type_archive( 'kellen_people' ) || is_tax( 'people-category' ) )
return 'kellen_people';
return false;
}
add_filter( 'template_include', 'be_template_chooser' );
/**
* Template Chooser
* Use CPT archive templates for taxonomies
* @author Bill Erickson
* @link http://www.billerickson.net/code/use-same-template-for-taxonomy-and-cpt-archive/
*
* @param string, default template path
* @return string, modified template path
*
*/
function be_template_chooser( $template ) {
if ( be_return_archive_section() )
$template = get_query_template( 'archive-' . be_return_archive_section() );
return $template;
}
add_filter( 'body_class', 'be_section_body_classes' );
/**
* Section Body Classes
* @author Bill Erickson
*
* @param array $classes
* @return array
*/
function be_section_body_classes( $classes ) {
if( be_return_archive_section() )
$classes[] = 'section-' . be_return_archive_section();
return $classes;
}
// Create Client Categories taxonomy to use with Kellen_Clients custom post type
add_action( 'init', 'create_clients_taxonomy', 0 );
function create_clients_taxonomy() {
$labels = array(
'name' => _x( 'Client Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Client Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Client Categories' ),
'all_items' => __( 'All Client Categories' ),
'parent_item' => __( 'Parent Client Category' ),
'parent_item_colon' => __( 'Parent Client Category:' ),
'edit_item' => __( 'Edit Client Category' ),
'update_item' => __( 'Update Client Category' ),
'add_new_item' => __( 'Add New Client Category' ),
'new_item_name' => __( 'New Client Category Name' ),
'menu_name' => __( 'Client Categories' ),
);
register_taxonomy('client_category',array('kellen_clients'), array(
'hierarchical' => true,
'labels' => $labels,
'has_archive' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'client-category' ),
));
}
//* Create Kellen Clients custom post type
add_action( 'init', 'create_client_type' );
function create_client_type() {
$labels = array(
'name' => 'Clients',
'singular_name' => 'Client',
'add_new' => 'Add New',
'add_new_item' => 'Add New Client',
'edit_item' => 'Edit Client',
'new_item' => 'New Client',
'view_item' => 'View Client',
'search_items' => 'Search Clients',
'not_found' => 'No ebooks found',
'not_found_in_trash' => 'No Clients found in trash',
'parent_item_colon' => '',
'menu_name' => 'Clients'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'clients'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-admin-users',
'taxonomies' => array( 'client_category' ),
'supports' => array('title','thumbnail','editor', 'genesis-cpt-archives-settings')
);
register_post_type( 'kellen_clients', $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment