Show custom posts on archive page organized by category/subcategory
-
I have a custom post type called “project” and a custom taxonomy called “project_category”. On the custom taxonomy archive page (taxonomy-project_category.php) I would like to show the following:
Parent Category Title (the category for the archive page you’re on)
Parent Category Description- title/link to custom post in parent category
- title/link to custom post in parent category
- title/link to custom post in parent category
Subcategory Title
- title/link to custom post in subcategory
- title/link to custom post in subcategory
- title/link to custom post in subcategory
Here is the code I’ve got so far, but all it does is display ONE list of items in both the parent category and subcategory. Is there a way to break out the subcategories into their own list with the subcategory name above it?
<?php $projcat = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $projects = new WP_Query( array( 'post_type' => 'project', // Tell WordPress which post type we want 'posts_per_page' => '100', // Show all posts 'tax_query' => array( array( 'taxonomy' => 'project_category', 'field' => 'slug', 'terms' => $projcat->slug, ) ) ) ); ?> <h2><?php echo $projcat->name; ?></h2> <p><?php echo $projcat->description; ?></p> <?php while ( $projects->have_posts() ) : $projects->the_post(); ?> <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> <?php endwhile; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Show custom posts on archive page organized by category/subcategory’ is closed to new replies.