I'm trying to get my head around CPT and Taxonomies. I've created a section on my WP site called Work and so I've got this in my functions.php file:
add_action('init', 'work_register');
function work_register() {
$labels = array(
'name' => _x('Work', 'post type general name'),
'singular_name' => _x('Work Item', 'post type singular name'),
'add_new' => _x('Add New Work Item', 'portfolio item'),
'add_new_item' => __('Add New Work Item'),
'edit_item' => __('Edit Work Item'),
'new_item' => __('New Work Item'),
'view_item' => __('View Work Item'),
'search_items' => __('Search Work'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail'),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
);
register_post_type('work' , $args );
}
register_taxonomy("work-categories", array("work"), array("hierarchical" => true, "label" => "Work Categories", "singular_label" => "Work Category", "rewrite" => true));
And I think I've got all of that right as I've got a section in my admin where I can add Work items. I wasn't sure whether to include this line:
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
because I want to create a new taxonomy called 'work categories' hence registering this at the end of my code using
register_taxonomy("work-categories", array("work"), array("hierarchical" => true, "label" => "Work Categories", "singular_label" => "Work Category", "rewrite" => true));
The admin screen displays a column for Categories and Tags, but not one for Work Categories - How do I ditch the columns for Categories and Tags and add a column for Work Categories??? What else do I need to add to my functions.php file to do this??
Also I want to know how I will be able to lists my Work Categories within my sidebar on my index-work.php and single-work.php pages.
-----EDIT-----
I've added the following code to my index-work.php and single-work.php pages just before calling the sidebar:
<h1>Categories</h1>
<?php
$taxonomy = 'work-categories';
$queried_term = get_query_var($taxonomy);
$terms = get_terms($taxonomy, 'slug='.$queried_term);
if ($terms) {
echo '<ul>';
foreach($terms as $term) {
echo '<li><a href="'.get_term_link($term, $taxonomy).'">'.$term->name.'</a></li>';
}
echo '</ul>';
}
?>
And this now outputs my Work Categories, but the links for these are /work-categories/artists/ for example which is fine, but they use the archive.php page - how can I get them to link to a page I've created? I've tried archive-artists.php but this isn't picked up. I don't want to use the blog archive.php page to display my work categories. Any ideas???
-----END EDIT-----
Thanks
E