title: WordPress - Retrieve featured images for posts listed by category
body: <p>I am new to WordPress and have successfully retrieved three posts for every category and listed them. I also want to retrieve the featured image for every post. I have tried out the following code in the <code>index.php</code> file. The code retrieved the three posts as I have mentioned, but the code to retrieve the images just appeared as plain text on the website, so I assume I have some syntax error. Can anyone help me out? Any help is appreciated.</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  //get all terms (e.g. categories or post tags), then display all posts in each term
  $taxonomy = 'category';//  e.g. post_tag, category
  $param_type = 'category__in'; //  e.g. tag__in, category__in
  $term_args=array(
    'orderby' =&gt; 'name',
    'order' =&gt; 'ASC'
  );
  $terms = get_terms($taxonomy,$term_args);
  if ($terms) {
    foreach( $terms as $term ) {
      $args=array(
        "$param_type" =&gt; array($term-&gt;term_id),
        'post_type' =&gt; 'post',
        'post_status' =&gt; 'publish',
        'posts_per_page' =&gt; 3,
        'caller_get_posts'=&gt; 1,
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query-&gt;have_posts() ) {
        echo 'List of Posts in '.$taxonomy .' '.$term-&gt;name;
        while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;
          &lt;p&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/p&gt;
  
  
  
  if (has_post_thumbnail($post-&gt;ID)) {
          $retina  = wp_get_attachment_image_src( get_post_thumbnail_id( $post-&gt;ID ), 'homepage-thumb-retina' );
          echo '&lt;img src="' . $retina[0] . '" alt="' . the_title() . '" width="24" height="24" /&gt;' ;
  };
  
         &lt;?php
        endwhile;
      }
    }
  }
  wp_reset_query();  // Restore global post data stomped by the_post().
  ?&gt;
  </code></pre>