1. $parent = get_cat_ID( 'photos' );
  2.  
  3. if ( is_category( $parent ) ) {
  4.     $cats = get_categories( 'child_of=' . $parent );
  5.  
  6.     foreach ( $cats as $cat ) {
  7.         query_posts( array (
  8.             'showposts' => 1,
  9.             'orderby'   => 'rand',
  10.             'cat'       => $cat->term_id
  11.         ) );
  12.  
  13.         if ( have_posts() ) :
  14.             while ( have_posts() ) :
  15.                 the_post();
  16.  
  17.                 $image = '';
  18.                 if ( has_post_thumbnail() )
  19.                     $image = get_the_post_thumbnail( get_the_ID() );
  20.  
  21.                 echo '<ul>';
  22.                 printf( '<li>%s<a href="%s">%s</a></li>',
  23.                     $image,
  24.                     get_category_link( $cat->term_id ),
  25.                     apply_filters( 'get_term', $cat->name ) );
  26.                 echo '</ul>';
  27.             endwhile;
  28.         else:
  29.             // CATEGORY HAS NO POSTS
  30.         endif;
  31.     }
  32. } else {
  33.     // CATEGORY DOESN'T EXIST
  34. }