Hi there,
I have created a custom post type and a custom taxonomy type with two levels of taxonomies. Let me make it clear with the following example:
Custom post type: Movie
Custom taxonomy type: Genres
Custom taxonomy lists:
- Comedy
- Comedy sub genre 1
- Comedy sub genre 2
- Action
- Action sub genre 1
- Action sub genre 2
- Sci-Fi
- Sci-Fi sub genre 1
- Sci-Fi sub genre 2
What I want to achieve is the following:
1) When going to the Genre-archive, it should display the main level taxonomies (Comedy, Action, Sci-Fi);
2) When going to the Comedy-archive, it should display the sub genres;
3) When going to the sub genre-archive, it should display all movies in that custom genre.
I have achieved step 3 by using the following code:
<?php
$term = $wp_query->queried_object; get_term( $term->slug, 'genres', '', '' ) ;
query_posts( array( 'post_type' => 'movie', 'genres' => $term->slug ) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; endif; wp_reset_query(); ?>
Using the code below, I am able to display a full tree view of all my taxonomies:
<?php
//list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
$taxonomy = 'genres';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$hide_empty = 0;
$title = '';
$parent = '';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'child_of' => $parent,
'hide_empty' => $hide_empty,
'title_li' => $title
);
?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>
What I am thus looking for is an archive template file that does the following:
1) Check if it is a main level taxonomy. Yes => show a list of the sub taxonomies
2) Check if it is a sub-taxonomy. Yes => show a list of the posts in this sub-taxonomy.
Anyone know if this is possible?
Thanks a lot!