WordPress.org

Support

Support » How-To and Troubleshooting » Show custom posts on archive page organized by category/subcategory

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)
  • 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)

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

    esmi

    @esmi

    Forum Moderator

    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.

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.
Skip to toolbar