Template for custom post with custom taxonomy

The theme that I’m developing is basically a portfolio, where the projects are custom post type and they are divided in categories (custom taxonomies). Here is how I’m defining both:

$labels = array(
    'name' => _x('My Portfolio', 'post type general name'),
    'singular_name' => _x('Portfolio Item', 'post type singular name'),
    'add_new' => _x('Add New', 'portfolio item'),
    'add_new_item' => _x('Add New Portfolio Item', 'add new portfolio item'),
    'edit_item' => _x('Edit Portfolio Item', 'edit portfolio item'),
    'new_item' => _x('New Portfolio Item', 'new portfolio item'),
    'view_item' => __('View Portfolio Item'),
    'search_items' => __('Search Portfolio'),
    '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,
    'menu_icon' => null,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array(null)
);
register_post_type('portfolio', $args);

register_taxonomy('project_category', array('portfolio'), array(
    'hierarchical' => true,
    'label' => "Project Categories",
    'singular_label' => "Project Category",
    'rewrite' => true
));

So in the homepage I’m listing all terms for the tax. “project_category” and I want a template file for a single term (for example, “jQuery Plugins” or “WordPress Themes”) where I can list all project with that term.

Read More

I looked in the WP template hierarchy and I believe the template that I need is

taxonomy-$taxonomy.php

My file is named taxonomy-project_category.php and it doesn’t find it. I also tried with taxonomy.php, term.php, archive.php … no success. I think the problem is with the links:

<a href="<?php echo $term->slug; ?>"><?php echo $term->name; ?></a>

Any ideas?
Cheers

Related posts

Leave a Reply

3 comments

  1. It seems from the OPs answer that the problem was not to do with the template, but using an incorrect url.

    To get the link of a taxonomy term you can use get_term_link():

      <a href="<?php echo get_term_link($term,'product_category')?>"><?php echo $term->name; ?></a>
    
  2. The taxonomy templates support taxonomy-{taxonomy}-{slug}.php so have you tried:

    taxonomy-project_category-jquery-plugins.php  
    // for the term Jquery Plugins, please alter to actually match what your term slug is
    

    That name format looks a little weird, you might want to consider using project-category instead.

    Also turn on debugging and install the debug bar.

  3. I found the solution myself, I’m posting this just in case anyone finds this question.

    The problem was in the link, this is how it should look like:

    <a href="<?php echo get_bloginfo('url') . '/project_category/' . $term->slug; ?>"><?php echo $term->name; ?></a>