Title: a conditional statement for the post id?
Last modified: August 19, 2016

---

# a conditional statement for the post id?

 *  [nickbudden](https://wordpress.org/support/users/nickbudden/)
 * (@nickbudden)
 * [16 years ago](https://wordpress.org/support/topic/a-conditional-statement-for-the-post-id/)
 * Hi,
 * I have my most recent posts listed in my sidebar and am trying to figure out 
   dynamic menu highlighting for the post when selected. My sidebar code looks like
   this:
 * <h2>WORK</h2>
    <?php query_posts(‘category=work&showposts=15’); ?> <?php if (
   have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
 *  <div id=”post-<?php the_ID(); ?>”>
 * </h3>
 *  <?php endwhile; ?>
 *  <?php else : ?>
 *  <?php endif; ?>
    </div>
 * I would like to put a conditional tag on the h3 tag of my post so that if we 
   are viewing the post is becomes <h3 class=”current”>. I imagine it would be something
   like <h3 <?php if…class=\”current\””>> but I can’t figure out the conditional
   tag. I feel it may be a problem because the actual post it in another loop. Has
   anyone any experience with something like this?
 * Thank you for any help, it is very much appreciated.
 * Nick

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years ago](https://wordpress.org/support/topic/a-conditional-statement-for-the-post-id/#post-1533375)
 * when the sidebar code is called after the main column loop, you could try to 
   save the post id of the center column in a variable, and check this in your if
   statement:
 *     ```
       <?php $main_post_id = $post->ID; ?>
   
       <h2>WORK</h2>
       <?php query_posts('category=work&showposts=15'); ?>
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <div id="post-<?php the_ID(); ?>">
   
       <h3 <?php if( get_the_ID() == $main_post_id ) { echo ' class="current"'; } ; ?>><a href="...."><?php the_title(); ?></a></h3>
   
       <?php endwhile; ?>
   
       <?php else : ?>
   
       <?php endif; ?>
       </div>
       ```
   
 * and in style.css:
    `h3.current a { color:#123456; }`
 *  Thread Starter [nickbudden](https://wordpress.org/support/users/nickbudden/)
 * (@nickbudden)
 * [16 years ago](https://wordpress.org/support/topic/a-conditional-statement-for-the-post-id/#post-1533379)
 * Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘a conditional statement for the post id?’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [nickbudden](https://wordpress.org/support/users/nickbudden/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/a-conditional-statement-for-the-post-id/#post-1533379)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
