You can get a random post by category by using the following code:
query_posts( array (
'showposts' => 1,
'orderby' => 'rand',
'cat' => $cat->term_id
) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
...
And then use get_the_post_thumbnail() to retrieve the post featured image:
if ( has_post_thumbnail() )
$image = get_the_post_thumbnail( $post_id );
Your final code could look like this:
$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 '<ul>';
printf( '<li>%s<a href="https://wordpress.stackexchange.com/questions/79978/%s">%s</a></li>',
$image,
get_category_link( $cat->term_id ),
apply_filters( 'get_term', $cat->name ) );
echo '</ul>';
endwhile;
else:
// CATEGORY HAS NO POSTS
endif;
}
} else {
// CATEGORY DOESN'T EXIST
}