• I’m currently working on a website which contains a custom posttype ‘Resources’ with custom taxonomy ‘resource_category’.
    The archive-page of this custom posttype should display all the parent-categories, subcategories and posts they contain.
    something like this:

    -Parent-category
    –sub-category
    —Post (title, link & excerpt)
    —Post
    –sub-category
    —Post
    -Parent-category
    –sub-category
    —Post
    —Post

    This is what i currently have:

    <?php
    $args = array(
      'orderby' => 'name',
      'order' => 'ASC',
      'taxonomy' => 'resource_category',
      );
    $categories = get_categories($args);
    foreach($categories as $category) { ?>
    <section>
    <div class="container"><div class="col1">
    <h3><?php echo $category->name; ?></h3>
    <?php $descendants = get_categories(array('child_of' => $category->term_id)); ?>
    <?php foreach ($descendants as $child) {
    $sub_args = array(
    'cat'      => $child->term_id,
    'order'    => 'ASC'
    ); query_posts( $sub_args );?>
    <h4><?php echo $child->cat_name; ?></h4>
    <ul>
    <?php while (have_posts()): the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php the_excerpt(); ?></li>
    <?php endwhile; ?>
    </ul>
    <?php } ?>
    </div></div>
    </section>
    <?php }; ?>

    But it doesn’t seem to work.
    Is there a way i can do this?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show posts of subcategories inside parent-categories’ is closed to new replies.