1). Inside your foreach
(term child) loop you first have:
echo wp_get_attachment_image( $termThumb->image_id, 'thumb' ) ;
but $termThumb
isn’t set yet. So on the first iteration it doesn’t do anything.
2) Then you have another foreach
loop:
if ( ! empty( $termThumbs ) ) {
foreach( $termThumbs as $termThumb ) {
print wp_get_attachment_image( $termThumb->image_id, 'thumb' ) ;
}
}
where $termThumbs
is (presumably) an array of term-thumbnail objects. So you print every term thumbnail image.
Then on the next iteration of the foreach
(i.e. the for the next term child) $termThumb
is now set to the last object in the $termThumbs
array. And so in (1) the term is now set, and so prints the thumbnail for that object, before doing (2) again displaying all thumbnails again.