rendered paste body<?php$numposts = 5; // # posts to display; -1 for all$cat_obj = $wp_query->get_queried_object();if( $cat_obj->parent ) :?><?php $child_posts = get_posts('category=' . $cat_obj->term_id . '&numberposts=' . $numposts); if( $child_posts ) :?> <li><h2><?php echo $cat_obj->name; ?></h2> <ul><?php foreach( $child_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?> </ul> </li><?php endif; else : ?> <li><h2><?php echo $cat_obj->name; ?></h2></li> <?php global $wpdb; $categories = $wpdb->get_results("SELECT $wpdb->terms.term_id, $wpdb->terms.name from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE taxonomy = 'category' AND parent = '{$cat_obj->term_id}' ORDER BY name ASC"); foreach($categories as $category) : $child_posts = get_posts('category=' . $category->term_id . '&numberposts=' . $numposts); if( $child_posts ) : ?> <li><h2><?php echo $category->name; ?></h2> <ul> <?php foreach( $child_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; endif; ?> </ul> </li> <?php endforeach; endif; ?>