title: How do I call and display a featured image linked to its post in Wordpress?
body: <p>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.</p>
  
  <p>Here's the code I'm working with</p>
  
  <pre><code>&lt;?php
      $featured_posts = get_posts('numberposts=4&amp;category=2');
  
      foreach( $featured_posts as $post ) {
          $custom_image = get_post_custom_values('featured_image', $post-&gt;ID);
          $image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/img/no_featured.jpg";
          printf('&lt;li&gt;&lt;a href="%s" title="%s"&gt;&lt;img src="%s" alt="%s" /&gt;&lt;/a&gt;&lt;/li&gt;', get_permalink($post-&gt;ID), $post-&gt;post_title, $image, $post-&gt;post_title);
      }
      ?&gt;    
  </code></pre>
  
  <p>All I want to do is get it to grab the posts featured image instead of that custom value.<br /> I'm sure there's a simple fix for this, I just haven't had any success yet, I always end up breaking it.</p>