Hi i'm using this code below, which links the title of the post to the first attachment in the post. But how do I change it so that it grabs the thumbnail instead?
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'offset' => 0,
'orderby' => 'menu_order',
'order' => 'asc',
'post_status' => null,
'post_parent' => $post->ID,
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
if(wp_attachment_is_image( $attachment->ID )) {
echo '<a href="'. get_attachment_link($attachment->ID) . '">'. get_the_title() .'</a>';
break;
}
}
}
else {
echo ''. get_the_title() .'';
};
?>
EIDT: Just as the title link goes to the attachment page of the first image, i want the thumbnail to do the same.
so instead of '.get_the_title().'</a>'
i want to get the thumbnail attached to the post.