Archive show thumbnail

You can check if the post as a thumbnail and if not the get the first image in the post ex:

<?php
$size="thumbnail";
if ( has_post_thumbnail() ) {
    ?>
    <a href="https://wordpress.stackexchange.com/questions/58503/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
        <?php the_post_thumbnail($size, array('class' => 'alignleft')); ?>

   <?php
} else {
    $attachments = get_children( array(
        'post_parent' => get_the_ID(),
        'post_status' => 'inherit',
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'order' => 'ASC',
        'orderby' => 'menu_order ID',
        'numberposts' => 1)
    );
    foreach ( $attachments as $thumb_id => $attachment ){ //this was missing
        ?>
        <a href="https://wordpress.stackexchange.com/questions/58503/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
        <?php echo wp_get_attachment_image($thumb_id, $size); ?>
        </a>
        ?>
    }
}
?>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)