WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a videosite based on wordpress. I would like it to show a icon on the posts from today. I've tried googling it, but without any succes at all. Any ideas on how to do it or maybe someone has a link to a tutorial on it?

Thanks in advance :-)

share|improve this question
up vote 0 down vote accepted

you can use the difference between the post time (get_the_time()) and the current time (date()) -

for instance, this snippet added to functions.php of your theme would add a new css class to post_class() if the post is less than 24hrs old:

function post_from_today_class($class) {
//add .new-post-today to post_class() if newer than 24hrs
    global $post;
    if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ) $class[] = 'new-post-today';
    return $class;


you can use the .new-post-today class to style something differently in your post div.

the core idea is:

if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ) { /*do something*/ };

edit: alternatively, direct in a template with its own php tags, use:

<?php if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ) : ?>text<?php endif; ?>
share|improve this answer
Thanks for your reply! I've put the code in functions, but then adding this to the loop: <?php if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ) { /*do something*/ }; ?> test <?php endif; ?> i get the following error Parse error: syntax error, unexpected T_ENDIF in public_html/wp-content/themes/WPTube4/index.php on line 82 – Torben Mar 1 '12 at 20:08
Remove the curly braces ("{}") and insert a colon before /*do something*/. – Joseph Leedy Mar 1 '12 at 20:22
if you want to use the one-liner code in the loop, don't add the larger code to functions.php. the error is from adding extra text and an 'endif' after the code; I'll edit my answer. just see, that @Joseph answered it already. – Michael Mar 1 '12 at 20:23
As you may have figured out by now, i'm pretty much a noob. Thanks for your patience :-) The code now looks like this: <?php if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ); ?> test <?php endif; ?> And gives me the following error: Parse error: syntax error, unexpected T_ENDIF in /var/www/titanen.dk/public_html/spillersmart/wp-content/themes/WPTube4/index.php on line 82 – Torben Mar 1 '12 at 20:28
What should "close" the function, if not <?php endif; ?>? – Torben Mar 1 '12 at 20:29

Your Answer


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.