You just need to tweak the logic so that if ( have_posts() ) :
is only run if get_term_children()
is empty, which it will be on the lowest level:
$term = get_queried_object();
$term_id = $term->term_id;
$taxonomy_name = $term->taxonomy;
$termchildren = get_term_children( $term_id, $taxonomy_name );
if ( ! empty( $termchildren ) ) {
echo '<ul>';
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
echo '<li><a href="' . get_term_link( $term, $taxonomy_name ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
} elseif ( have_posts() ) {
while ( have_posts() ) : the_post();
get_template_part( 'content', 'oferta' );
endwhile;
twentytwelve_content_nav( 'nav-below' );
} else {
get_template_part( 'content', 'none' );
}
In that example I added if ( ! empty( $termchildren ) )
and changed if ( have_posts() )
to elseif ( have_posts() )
.