My final code looks like:
<?php
$parent = get_cat_ID("photos");
$cats = get_categories("child_of=".$parent);
foreach ($cats as $cat) {
query_posts("posts_per_page=1&orderby=rand&cat=".$cat->cat_ID);
?>
<?php if ($parent == true && have_posts()) : while (have_posts()) : the_post(); ?>
<ul>
<?php if (has_post_thumbnail()) { ?>
<?php
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>',
apply_filters('get_term', $cat->name));
?>
<?php } ?>
</ul>
<?php endwhile; endif; } ?>
<?php if (! $parent == true || ! $cat == true) { ?>
<p><?php _e("Sorry, no posts matched your criteria."); ?></p>
<?php } ?>
<?php wp_reset_query(); ?>
Basically, in this version a couple of things changed:
I changed the if
to make sure that the parent category exists and that we have a post, if both of those conditions are met then it will display my content...if not, it does nothing.
Since the else
wasn't working I wrote my own...that says...if the parent category or the child category doesn't exist than display my error message...if so, than do nothing.
Not sure why the else doesn't work, but my guess is it's because of the foreach
that's the only thing that's different in this loop, that's not in most other loops.
Hope this helps someone else :)
Thanks Mike for all your help!!
*P.S. - I will be marking your solution as the answer, as it did answer my initial question :)
Josh