Title: Highlighting current post
Last modified: August 18, 2016

---

# Highlighting current post

 *  Resolved [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/)
 * I have a page that currently lists posts on a table row (like a nav). I would
   want to highlight the current row based on the what page the user is on.
 * —–
    article 1 —– article 2 —– article 3 highlighted (user is on article 3 page)—–
 * Been trying to look for a solution everywhere but have yet to come up with one.
 * Any help would be appreciated.

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

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509916)
 * Fisrt we should clarify are you talking about posts or Pages?
 *  Thread Starter [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509917)
 * Posts
 *  Thread Starter [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509955)
 * /bump
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509957)
 * Don’t bump after an hour or two!
    Patience is highly appreciated by the volunteer
   helpers. Probably nobody came around that has an answer for your question. For
   sure, I don’t.
 *  [Xander](https://wordpress.org/support/users/xander/)
 * (@xander)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509962)
 * Perhaps you could elaborate on the details? Sounds like you are trying to do 
   some custom work here, and using the post ID might be the way to go. It’s hard
   to say without knowing the context though.
 *  Thread Starter [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509970)
 * Sorry about bumping to quick.
 * To elaborate, here is the code Im using to output the posts.
    ` <? $pageid="post-
   <?php the_ID(); ?>"; ?> <ul> <?php $lastposts = get_posts('numberposts=20'); 
   foreach($lastposts as $post) : setup_postdata($post); ?> <li> <a href="<?php 
   the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a> </
   li> <?php endforeach; ?> </ul>  All I basically want is to have a css class applied
   to the list. Ive tried the following below.  <? $pageid="post-<?php the_ID();?
   >"; ?> <ul> <?php $lastposts = get_posts('numberposts=20'); foreach($lastposts
   as $post) : setup_postdata($post); ?> <li <? if("post-<?php the_ID(); ?>"==$pageid){
   echo 'id="current"';}?>><a href="<?php the_permalink(); ?>" id="post-<?php the_ID();?
   >"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>  The problem with
   this is that all outputed links are highlighted.
 *  Thread Starter [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509987)
 * Please mark this as solved. I have found the solution.
 * I just added a css property to match the post id
 * `
    <style type="text/css"> #post-<?php the_ID(); ?> { background-color: #FFFFFF;}
   </style> <li class="post-<?php the_ID(); ?>"> <a href="<?php the_permalink();?
   >" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a> </li>
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-509988)
 * You should mark it solved 🙂
    (up where the title is)
 *  [keasone](https://wordpress.org/support/users/keasone/)
 * (@keasone)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-510485)
 * sory, i don`t get this -if i try this solution, all links are highlighted`?
 *  [kaeloz](https://wordpress.org/support/users/kaeloz/)
 * (@kaeloz)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-510522)
 * I used the code of machinetype (thanks), but instead of highlight like this:
 * post 1
    post 2 “post 3 highlight” post 4
 * Put some other title down the other post title, like this:
 * post 1
    post 2 post 3 post 4 “post 3 highlight”
 * Is that what it spouse to do, or I put it wrong?

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

The topic ‘Highlighting current post’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 5 participants
 * Last reply from: [kaeloz](https://wordpress.org/support/users/kaeloz/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/highlighting-current-post/#post-510522)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
