6

I have a custom content type, "products", which shares the category taxonomy with posts. We're using posts to discuss and review products. The idea is to have two separate URLs:

  • /discussion/category/term/ : Displays a listing of posts belonging to a specific term with a "related products" area pulling from the same term
  • /products/category/term/ : Displays a listing of products belonging to that term with a "related discussions" area pulling from the same term

I can use the default category/archive templates with a permalink front for posts, and the first is solved by default. But since each taxonomy only has one template set, how can I achieve the second?

The above URLs are examples, and all archive types would ideally work with the normal permalink structures after the initial front/slug.

Looking at similar questions, I've seen suggestions to use two different taxonomies with the same terms, but as of WordPress 3.7 terms of two different taxonomies can no longer share a slug, so relating the two is problematic for a non-technical site manager.

I also know how to use get_query_var('post_type') to differentiate the two post types, but that doesn't solve the issue of separate URLs.

Any help is greatly appreciated!

1 Answer 1

0

According to the WordPress Codex

archive-{post_type}.php

So, in your case (depending on your naming):

archive-products.php

If you have a custom taxonomy archive also, then the challenge is structuring your archive to represent the proper taxonomy template.

If you need to have a custom taxonomy archive, I would recommend that you use the post-type archive structure above, and then within the archive file, determine the taxonomy that is being used, and load a template part.

Sample psuedo-code (on archive-products.php):

$tax = get_query_var( 'taxonomy' );
$term = get_query_var( 'term' );
if ($tax == 'your_taxonomy') {
    get_template_part('my_slug', 'my_name');
} else {
    // get the default template part...
}
2
  • I initially misunderstood your response based on "determine the taxonomy that is being used"; there's only a single taxonomy. But your code implies "determine the term being used", which is interesting- presumably I then alter my query to restrict to that term. I'll give it a try.
    – Marc
    Commented Jun 4, 2014 at 17:25
  • So this is a non-starter so far, due to URL issues. It doesn't seem like I can specify a URL that gives a post type archive and also specifies a taxonomy- I just get a 404. Any ideas?
    – Marc
    Commented Jun 4, 2014 at 18:34

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.