I have a site that has two different bodies of content: more formal content (using various different custom post types) and a blog (using a blog post type). These two different bodies of content use the same taxonomiesâbut I would like to have two different versions of the taxonomy archives: one for the formal content, and one for blog content.
For example, for a term science in the taxonomy subjects I’d like to have both
- mysite.com/subjects/science AND
- mysite.com/blog/subjects/science (or mysite.com/subjects/science/blog)
What’s the best way to accomplish this in WordPress? I don’t want to use pages, because terms are being added all the time. I just want some way to be able to provide two archive templates for taxonomy terms.
My solution at the moment is to use a GET variable to request a different page template:
To handle the ?view=blog variable, I add this conditional to the top of taxonomy.php (or taxonomy-subjects.php and any other taxonomy-{slug} that I want to have an alternate version of):
Then, in the blog-archive.php template, I adjust the query_vars of $wp_query to output a loop with only blog posts.
This works for me at the moment; the only unfortunate aspect is that the URLs show ?view=blog instead of nice /blog. I borrowed the main $_GET[] idea from the answer here: How can I dynamically load another page template to provide an alternate layout of the posts?. (I wonder if the latter can be done more intuitively with $the_query = $wp_query->set(‘post_type’, ‘blog’); but this seemed to turn $the_query into a non-object and give an error.)
The easy way, though not the only one, is to just use the default hierarchy for archives.php
http://codex.wordpress.org/Template_Hierarchy
So for you blog archives, use
archives.php
or a taxonomy based template liketaxonomy-subject.php
.Whatever the case you will need to alter the loop query to only show the posts for the term “science” in the taxonomy “subjects” that are posted in the default blog (post).
Then for your custom post type archive you can create a template called
archive-{post_type}.php
(post type is the name you registered your CPT with). You can basically do the same custom query as above but only include posts in the custom post type ( and none from posts aka your blog).This is what you need to get familiar with for custom query’s, http://codex.wordpress.org/Class_Reference/WP_Query#Type_.26_Status_Parameters