Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
This link should help you out net.tutsplus.com/tutorials/wordpress/… –  user29421 Mar 24 '13 at 4:25
add comment

2 Answers

How about just using css ?

ol li:last-child {font-weight: 600}
share|improve this answer
    
Didn't know I could do that with CSS. I'll give it a try. –  Acornrevolution Mar 22 '13 at 15:25
add comment
up vote -1 down vote accepted

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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