Redirect category to first available child post

I had to do that, but only in some categories in my site.
This was the code I used – I put it in my theme’s functions.php:

  // use template_redirect action:
 add_action( 'template_redirect', 'my_redirect_to_post' );

 /// Function to redirect from certain category pages to first post of those categories
 function my_redirect_to_post() {
     if (is_category('3') ||  is_category('5') ) {
         $category = get_the_category();
         $posts =  query_posts('showposts=1&cat=".$category[0]->cat_ID);
         if(have_posts()) :
            wp_redirect(get_permalink($post->ID));
         endif;
    }
}

Of course, if you need to do it in all your categories, you can remove the condition if (is_category("3') || is_category('5') ).