0

I want to be able to highlight the most recent post in a list of recent posts. By highlight I mean bold or style slightly differently from the other posts. This is the code I use now:

<h2>Assignments</h2>
<ol>
<?php
    $recentPosts = new WP_Query();
    $recentPosts->query('showposts=15&cat=188&order=ASC');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>    </li>
<?php endwhile; ?>
</ol>

This simply returns a numbered list. I would like to style differently the most recent post (i.e. the last item on the list). How can this be done?

1

3 Answers 3

0

How about just using css ?

ol li:last-child {font-weight: 600}
1
  • Didn't know I could do that with CSS. I'll give it a try. Mar 22, 2013 at 15:25
0

As of today you can use Highlight New Posts to highlight new posts for your visitors.

It works with a cookie that stores the most recent time of visit of your visitor. It then checks if a post was published after the last visit and if so, appends a "NEW" label to the post title.

-1

I found a better solution:

<h2>Assignments</h2>
<ol>
<?php
  $recentPosts = new WP_Query();
  $recentPosts->query('showposts=15&cat=188&order=DESC');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<?php $ageunix = get_the_time('U');
$days_old_in_seconds = ((time() - $ageunix));
$days_old = (($days_old_in_seconds/86400));
?>
<?php if ($days_old > 3) : ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>    </li>
<?php else : ?>
<li><strong><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></strong></li>
<?php endif; ?>
<?php endwhile; ?>
</ol>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.