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.

I have post type 'product' and hierarchical taxonomy 'types' attached to it. In this taxonomy, I have terms: 'dry-clean', 'washer', etc. With several sub terms on each terms.

In my situation, I need to display, eg:

  1. http://example.com/types/washer -> display all sub terms on it
  2. http://example.com/types/washer/{subterm} -> display all posts on it

My questions is:

  1. How do I get permalink URL for parent terms? I try URL above, but it result in 404.
  2. How the template files work for that kind of problem?
    1. is taxonomy-types-washer.php enough for case #1? or should I create taxonomy-types.php and create the logic there?
    2. in my mind, after scanning template hierarchy, I might need taxonomy-types-{term_parent}.php to list all sub terms and taxonomy-types.php to list all product in sub terms.
    3. ultimately, to display each product, I will have to create single-product.php
  3. On a slightly unrelated problem. I find that archive-{posttype}.php doesn't work when I don't have any post on it. Is there any solution for this? (should I create different question, or stick with this one)?

UPDATE

I checked my rewrite_rules options and it doesn't list [types] at all. I don't know why. To test it, I change my slug into product-types, flush permalink and it list this:

[product-types/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?types=$matches[1]&feed=$matches[2]
[product-types/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?types=$matches[1]&feed=$matches[2]
[product-types/([^/]+)/page/?([0-9]{1,})/?$] => index.php?types=$matches[1]&paged=$matches[2]
[product-types/([^/]+)/?$] => index.php?types=$matches[1]

So I guess it's registered now. I try to load URL product-types/washer it goes to 404. I try to load URL index.php?types=washer. It too, goes 404. Right now, I have this files:

  • taxonomy-types-washer.php
  • taxonomy-types.php

So, I don't know what's wrong with this one :(.

UPDATE #2

I find the problem. It's because I missed 'rewrite'=>array('hierarchical'=>true)

Here's the new rewrite_rules:

[product-types/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?types=$matches[1]&feed=$matches[2]
[product-types/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?types=$matches[1]&feed=$matches[2]
[product-types/(.+?)/page/?([0-9]{1,})/?$] => index.php?types=$matches[1]&paged=$matches[2]
[product-types/(.+?)/?$] => index.php?types=$matches[1]
share|improve this question
    
I know this can be done wordpress.stackexchange.com/questions/5308/… but for "non-hierarchical" taxonomies. –  Bainternet Apr 11 '11 at 2:09
    
You should create a new question for point 3. –  scribu Apr 11 '11 at 3:09
    
@scribu, I'll create that question tonight, when I'm back home. –  ariefbayu Apr 11 '11 at 12:14
add comment

1 Answer 1

up vote 6 down vote accepted

These types of URLs are supported since WP 3.1:

register_taxonomy( 'types', 'post', array(
  'hierarchical' => true,
  'rewrite' => array( 'hierarchical' => true ),
  ...
);

Remember to flush the rewrite rules after making the change.

The template you would use for both parent and child terms is taxonomy-types.php:

$current_term = get_queried_object();

if ( 0 == $current_term->parent ) {
  // it's a parent term; display it's child terms using wp_list_categories() etc.
} else {
  // it's a child term; display the posts using The Loop etc.
}
share|improve this answer
    
many thanks, @scribu! –  ariefbayu Apr 11 '11 at 20:02
add comment

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.