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:
- http://example.com/types/washer -> display all sub terms on it
- http://example.com/types/washer/{subterm} -> display all posts on it
My questions is:
- How do I get permalink URL for parent terms? I try URL above, but it result in 404.
- How the template files work for that kind of problem?
- is
taxonomy-types-washer.php
enough for case #1? or should I createtaxonomy-types.php
and create the logic there? - in my mind, after scanning template hierarchy, I might need
taxonomy-types-{term_parent}.php
to list all sub terms andtaxonomy-types.php
to list all product in sub terms. - ultimately, to display each product, I will have to create
single-product.php
- is
- 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]
These types of URLs are supported since WP 3.1:
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: