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;
}
add_filter('post_class','post_from_today_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; ?>