Title: Highlight current post &#8211; Advanced Custom Fields
Last modified: August 20, 2016

---

# Highlight current post – Advanced Custom Fields

 *  [Rachel Goldstein](https://wordpress.org/support/users/rachelgoldstein71/)
 * (@rachelgoldstein71)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/)
 * I am using advanced custom fields, and the following code (see below) to display
   the last 5 posts, but need to change the link color of the current post you are
   viewing. Would appreciate any help (site is not live or I would post link).
 *     ```
       <div class="leftbar">
       <h3><a href="/blog"><img src="/wp-content/themes/ts/resources/up-arrow.gif" border="0" style="float:left; margin: 3px 5px 0 0;">T&S Blog Overview</a></h3>
       <?php
       $queryObject = new WP_Query( 'post_type=blog&posts_per_page=5' );
       // The Loop!
       if ($queryObject->have_posts()) {
           ?>
           <ul>
           <?php
           while ($queryObject->have_posts()) {
               $queryObject->the_post();
               ?>
   
               <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
           <?php
           }
           ?>
           </ul>
   
           <?php
       }
       ?>
   
       </div><!-- end leftbar -->
       ```
   

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

 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410684)
 * Use a tool like [firebug](http://getfirebug.com/) or chrome developer tools to
   pinpoint any unique classes or identifiers.
 *  Thread Starter [Rachel Goldstein](https://wordpress.org/support/users/rachelgoldstein71/)
 * (@rachelgoldstein71)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410686)
 * I do use Firebug but there is no class on the current post link that is any different
   than the rest of the post links.
 *  [rencang_enggal](https://wordpress.org/support/users/rencang_enggal/)
 * (@rencang_enggal)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410704)
 * declare a class if you didn’t. firebug or another tool will show where is it.
 *  Thread Starter [Rachel Goldstein](https://wordpress.org/support/users/rachelgoldstein71/)
 * (@rachelgoldstein71)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410713)
 * I am not sure how to do that — it’s a template page for single posts, and the
   links of the last 5 posts are dynamically generated. How do you declare a class
   on the current post? (TIA).
 *  [rencang_enggal](https://wordpress.org/support/users/rencang_enggal/)
 * (@rencang_enggal)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410741)
 * for example, I assume using your script above.
    `<a href="/blog"><img src="">`
   you can declare like this: `<a href="/blog" class="current"><img src="">`
 * if you can’t find on your themes, maybe you can find on your functions file
 * CMIIW
 *  Thread Starter [Rachel Goldstein](https://wordpress.org/support/users/rachelgoldstein71/)
 * (@rachelgoldstein71)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410757)
 * The current post would be one of the 5 posts in the loop, not the main blog link.
   The code above pulls the most recent posts, with the same line of code for each.
   So that’s why I am not sure how to determine which of the 5 links in the loop
   is the current one for the single post page that I’m on.
 *  Thread Starter [Rachel Goldstein](https://wordpress.org/support/users/rachelgoldstein71/)
 * (@rachelgoldstein71)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410948)
 * I figured it out, and thought I would share here.
 *     ```
       <?php $this_post = $post->ID; ?>
   
       <?php
       $queryObject = new WP_Query( 'post_type=blog&posts_per_page=5' );
       // The Loop!
       if ($queryObject->have_posts()) {
           ?>
           <ul>
           <?php
           while ($queryObject->have_posts()) {
               $queryObject->the_post();
       	$lastFive = $post->ID;
   
               ?>
       	 <?php
       	   if ($this_post == $lastFive)  {
       	 ?>
       	   <li id="current"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
   
       	<?php
       	   }
       	   else  {
       	?>
       	   <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       	   <?php
       	   }
       	   ?>
           <?php
       }
       ?>
           </ul>
   
       <?php
       }
       ?>
       ```
   

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

The topic ‘Highlight current post – Advanced Custom Fields’ is closed to new replies.

## Tags

 * [css](https://wordpress.org/support/topic-tag/css/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [Rachel Goldstein](https://wordpress.org/support/users/rachelgoldstein71/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/highlight-current-post-advanced-custom-fields/#post-3410948)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
