1

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.

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

1
  • What happens if you go to www.yoursite.com?product_category=jquery-plugins? And what do you mean doesn't find it? Doesn't find the template or doesn't find the content? Commented May 5, 2012 at 18:10

3 Answers 3

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>
0

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.

0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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