title: Generate Background for Each Post With Wordpress Thumbnail
body: <p>I have a <a href="http://palatehack.com" rel="nofollow">website</a> that i'm working on where I need to generate a unique image in header.php for each individual post.</p>
  
  <p>I have this in my index.php:</p>
  
  <pre><code> $pageposts = $wpdb-&gt;get_results($querystr, OBJECT);
   foreach($pageposts as $ppost){
  $ID = $ppost-&gt;post_id;
  $title = get_the_title( $ID ); 
  $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $ID ), 'single_post_thumbnail' );
  $t = $thumb[0];
  $desc = get_post($ID)-&gt;post_content;
  $out = get_post_meta($ID,'outbound',true);
  $output = "
  &lt;div class='ph-sticky' id='phf'&gt;
  &lt;span class='icon-x'&gt;&lt;i class='fa fa-times icon-xy'&gt;&lt;/i&gt;&lt;/span&gt;
  &lt;div class='row hunt-row-fp'&gt;
  &lt;a class='title' href='$out' target='_blank' rel='nofollow'&gt;$title&lt;/a&gt;
  &lt;div class='img-featured'&gt;&lt;img class='phsi' src='$t'/&gt;&lt;/div&gt;
  &lt;span class='description'&gt;$desc&lt;/span&gt;
  &lt;/div&gt;
  &lt;/div&gt;";    
   }
  
   echo $output;
   wp_reset_query();
  ?&gt;
  </code></pre>
  
  <p>This correctly generates a thumbnail for each post, however in my header.php my code only generates the image of the FIRST post on the page. Here it is:</p>
  
  <pre><code>&lt;!-- post modal --&gt;
  &lt;div class="show-post-modal"&gt;  
  
  &lt;?php if (has_post_thumbnail( $post-&gt;ID ) ): ?&gt;
  &lt;?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post-&gt;ID ), 'large' ); ?&gt;
  &lt;div class="comments-bg-image" style="background-image: url('&lt;?php echo $image[0]; ?&gt;')" &gt;
  &lt;/div&gt;
  &lt;?php endif; ?&gt;
  
  &lt;div class="comments-header"&gt;
  </code></pre>
  
  <p>I've tried multiple solutions however I can only seem to pull in the first thumbnail, which becomes the background for all posts. Any help would be most appreciated!</p>