Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So,

I have my custom post type with the slug /news. And I want my category view to be /news/category/CATEGORYID.

For that I create my custom taxonomy:

add_action('init', 'create_allfilmnews_categories', 0);
function create_allfilmnews_categories() {
    $labels = array(
        'name' => _x( 'Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search categories' ),
        'all_items' => __( 'All category' ),
        'parent_item' => __( 'Parent category' ),
        'parent_item_colon' => __( 'Parent category:' ),
        'edit_item' => __( 'Edit category' ),
        'update_item' => __( 'Update category' ),
        'add_new_item' => __( 'Add new category' ),
        'new_item_name' => __( 'New category name' ),
        'menu_name' => __( 'News categories' ),
    );  

    register_taxonomy('news_category', 'news', array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'category' ),
    ));
}

I was hoping, that since it is hooked to news custom post-type.. and its slug is "category", so I was hoping that naturally it would work out like I wanted (/news/category/CATEGORYID). And use my custom category-template just by creating a file to the template directory: category-news_category.php.

However, of course it is not working.

Is it even possible to have a custom taxonomy aka. categories inside custom post-type, that work perfectly with permalinks?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Two things - I think the category URL would be: yourdomain.com/news_category/NEWS-CATEGORY-SLUG-HERE

So for example if you created a category "top headlines" in your "news_category" taxonomy... it would look like this (assuming the slug for "top headlines" is "top-headlines"):

/news_category/top-headlines/

The second thing... I think your template name should be "taxonomy-news_category.php"

(edited to add - I don't think you can have the slug be "category" as that is being used by WordPress already.. so that may be causing a conflict in itself...I could be wrong on that though...)

share|improve this answer
    
Your right on the money! I actually got this EXACTLY the same method working last night. My overall solution was, that the custom taxonomy slug was simply: "news/category" and indeed the template-name for custom taxonomy would be taxonomy-news_category.php Works 100% like I wanted. –  Kalle H. Väravas Dec 9 '11 at 15:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.