admin管理员组文章数量:1122846
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!
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!
Share Improve this question asked Jun 4, 2014 at 0:46 MarcMarc 712 bronze badges1 Answer
Reset to default 1According 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...
}
版权声明:本文标题:templates - How do I display two separate taxonomy archives for two post types that share a single taxonomy? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289941a1928407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论