$parent = get_cat_ID( 'photos' ); if ( is_category( $parent ) ) { $cats = get_categories( 'child_of=' . $parent ); foreach ( $cats as $cat ) { query_posts( array ( 'showposts' => 1, 'orderby' => 'rand', 'cat' => $cat->term_id ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); $image = ''; if ( has_post_thumbnail() ) $image = get_the_post_thumbnail( get_the_ID() ); echo ''; endwhile; else: // CATEGORY HAS NO POSTS endif; } } else { // CATEGORY DOESN'T EXIST }