title: highlighting current post in recent posts sidebar , wordpress
body: <p>Im just wondering how I could get the post id of the blog post I am currently reading while in another loop (i.e. the recent posts loop in the sidebar)</p>
  
  <p>In my single post php file I have this code creating a variable</p>
  
  <pre><code>&lt;?php while ( have_posts() ) : the_post(); ?&gt;
  
                  &lt;?php get_template_part( 'content', 'single' ); ?&gt;
                  &lt;?php $current_post_id = get_the_ID(); ?&gt; 
  
  
              &lt;?php endwhile; // end of the loop. ?&gt;
  </code></pre>
  
  <p>Then in my default-widgets php file, in the loop for recent posts I have this...</p>
  
  <pre><code>&lt;?php  while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt;
      &lt;?php $recent_post_id = get_the_ID(); ?&gt;
  
      &lt;li&gt; &lt;?php echo $recent_post_id; if ( $recent_post_id == $current_post_id ) { echo 'pass   '; } else { echo 'fail   ';} ?&gt;&lt;/li&gt;
      &lt;?php endwhile; ?&gt;
  </code></pre>
  
  <p>Its giving fail every time, so obviously what Im doing doesnt make sense (Im still learning). Im just wondering is there a way to grab the post id from the first loop, and use it in the second. At the moment when I echo <code>current_post_id</code> in the second loop nothing shows up.
  (Regarding highlighting the current post, that'll be easy once I get this working.</p>
  
  <p>Thanks for the help.</p>