WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Show custom posts on archive page organized by category/subcategory (4 posts)

  1. punkyb9
    Member
    Posted 10 months ago #

    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; ?>
  2. punkyb9
    Member
    Posted 10 months ago #

    Alternatively, if I could just display the sub-category name next to each entry that has one, that would also be great. I.E:

    Parent Category Title
    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 name)
    • title/link to custom post in parent category (subcategory name)
  3. dustmop
    Member
    Posted 4 weeks ago #

    I've been looking for this too, any update to a solution?

  4. esmi
    Forum Moderator
    Posted 4 weeks ago #

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else's topic.

    I am now closing this 9 month old topic as it references an older version of WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic