Title: php code for latest posts
Last modified: August 20, 2016

---

# php code for latest posts

 *  Resolved [Rolf Hassel](https://wordpress.org/support/users/samwan/)
 * (@samwan)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/php-code-for-latest-posts/)
 * I’m using WordPress as a classifieds website where people can post their ads.
   I would like to highlight the latest ads (posts). For example the latest ads (
   postings) in the past 24 hours or the latest in the past 7 days etc.
 * I know what i want to set in the css, but i dont know how the php code would 
   be. Can someone give an example on this?
 * I’m using the following code to highlight featured ads (sticky post):
 * <?php if(is_sticky($post_ID) == true) echo ‘<span class=”featured”></span>’; 
   else echo ”; ?>
 * Now i need something like that for the post of the last 7 days and the last 24
   hours.
 * Best Regards Rolf

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/php-code-for-latest-posts/#post-2673879)
 *     ```
       <?php  if(is_sticky($post_ID) == true) echo '<span class="featured"></span>';
       elseif( (date('U')-get_the_time('U')) <= 24*60*60) echo '<span class="one-day"></span>';
       elseif( (date('U')-get_the_time('U')) <= 24*60*60*7) echo '<span class="one-week"></span>';
       else echo ''; ?>
       ```
   
 * [http://codex.wordpress.org/Function_Reference/get_the_time](http://codex.wordpress.org/Function_Reference/get_the_time)
 *  Thread Starter [Rolf Hassel](https://wordpress.org/support/users/samwan/)
 * (@samwan)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/php-code-for-latest-posts/#post-2673891)
 * Thank you very much! That was **exactly** what i was looking for!

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

The topic ‘php code for latest posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Rolf Hassel](https://wordpress.org/support/users/samwan/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/php-code-for-latest-posts/#post-2673891)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
