Add this function to your functions.php:
<?php # Displays post image attachment (sizes: thumbnail, medium, full)
function dp_attachment_image($postid=0, $size='thumbnail', $attributes='',$echo=1) {
if ($postid<1) $postid = get_the_ID();
if ($images = get_children(array(
'post_parent' => $postid,
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
foreach($images as $image) {
$attachment=wp_get_attachment_image_src($image->ID, $size);
$img = "<img src='{$attachment[0]}' $attributes />";
if ($echo) {
echo $img;
} else {
return $img;
}
}
}?>
Use this to display your attachment:
<?php
$cat = 39; // Replace this with your own category id
query_posts("posts_per_page=1&caller_get_posts=1&cat=$cat");
if (have_posts()) : while (have_posts()) : the_post();
$link = get_category_link($cat);
$echo = 0;
$img = dp_attachment_image($post->ID,'full','width=90%',$echo);
if ($img) { ?>
<h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
<a href="<?php echo $link; ?>" > <?php echo $img; ?> </a>
<?php }
endwhile;
endif;
?>