I'm trying to display a list of the 4 most recent posts in a certain category on my home page, each displayed only by their featured image, and then when you click on one of the images it takes you to the full article/post. I found a tutorial that explains how to do this but it seems to predate thumbnails/featured images and uses custom values instead. I haven't been able to modify it to use featured images or find one that uses them.
Here's the code I'm working with
<?php
$featured_posts = get_posts('numberposts=4&category=2');
foreach( $featured_posts as $post ) {
$custom_image = get_post_custom_values('featured_image', $post->ID);
$image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/img/no_featured.jpg";
printf('<li><a href="%s" title="%s"><img src="%s" alt="%s" /></a></li>', get_permalink($post->ID), $post->post_title, $image, $post->post_title);
}
?>
All I want to do is get it to grab the posts featured image instead of that custom value.
I'm sure there's a simple fix for this, I just haven't had any success yet, I always end up breaking it.