Site icon Hip-Hop Website Design and Development

Displaying subcategories and then posts in taxonomy template

I have a custom post type ‘downloads’ which i have a have a custom template set up to get terms of to begin with. Im now trying to set up my taxonomy template so that it displays sub-categories if there are any, but if not to show posts for that term.

Below is what my taxonomy template includes so far and this works fine to the point that it displays the child categories, but it doesnt then show the posts for that category at the end. Id like it so that if there are child categories then show them, else show the posts for that category.

<?php
                $term = get_queried_object();
                $term_id = $term->term_id;
                $taxonomy_name = $term->taxonomy;

                $termchildren = get_term_children( $term_id, $taxonomy_name );?>

                        <?php foreach ( $termchildren as $child ) {
                        $term = get_term_by( 'id', $child, $taxonomy_name ); ?>
                            <li>
                              <?php echo $term->name; ?>
                              <?php echo $term->description; ?>
                            </li>
<?php } ?>