1. <?php
  2.     $parent = get_cat_ID("photos");
  3.     $cats = get_categories("child_of=".$parent);
  4.     foreach ($cats as $cat) {
  5.     query_posts("posts_per_page=1&orderby=rand&cat=".$cat->cat_ID);
  6. ?>
  7.     <?php if ($parent == true && have_posts()) : while (have_posts()) : the_post(); ?>
  8.         <ul>
  9.             <?php if (has_post_thumbnail()) { ?>
  10.                 <?php
  11.                     printf( '<li><a href="'.get_category_link($cat->cat_ID).'">'.get_the_post_thumbnail(get_the_ID(), "album-thumb").'</a><a href="'.get_category_link($cat->term_id).'">%s</a></li>',
  12.                     apply_filters('get_term', $cat->name));
  13.                 ?>
  14.             <?php } ?>
  15.         </ul>
  16.     <?php endwhile; endif; } ?>
  17.     <?php if (! $parent == true || ! $cat == true) { ?>
  18.         <p><?php _e("Sorry, no posts matched your criteria."); ?></p>
  19.     <?php } ?>
  20. <?php wp_reset_query(); ?>