
… or perhaps entries posted in the last 48 hours? Ever wanted to put a small image label next to your post telling readers “Hey, this post is barely 2 days old. It’s new!”
Of course, putting a new post label is nothing new. But again, this tiny feature does not come with default WordPress. Luckily with just one or two lines of PHP code, you can modify your WordPress theme to label your new entries automatically.
The following code sample shows how you can label your posts with a tiny image ‘new.gif’ if your post is less than 2 days old. Within your latest entries Loop, we’ll put the ‘new.gif’ image label right new to your post title:
...
...
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php if ( (time()-get_the_time('U')) <= (2*86400) ) { ?>
<img class="new_entry_label" src="<?php bloginfo('template_directory'); ?>/images/new.gif" alt="(New Entry)" title="(New Entry)" />
<?php } ?>
...
...
That’s it. Click here to see it in action on one of my WordPress theme demos. Notice how the newer posts’ title are labelled with a new.gif image.
Now for some explanation on the code used …
PHP time() function returns the current time in Unix Epoch format which looks like this:
12217984786
The function get_the_time('U') returns the entry posted time in Unix Epoch format. Now that both current time ( time() ) and entry posted time ( get_the_time(’U') ) is in Unix Epoch format, we can easily calculate the time difference by substracting current time with entry posted time;
time()-get_the_time('U')
Finally, we evaluate if the difference is less than 2 days (again converted to Unix Epoch format by multiplying with 86400 ), the condition is true and the tag is executed which puts “new.gif” image label next to your post title.
<?php if ( (time()-get_the_time('U')) <= (2*86400) ) { ?>
<img class="new_entry_label" src="<?php bloginfo('template_directory'); ?>/images/new.gif" alt="(New Entry)" title="(New Entry)" />
<?php } ?>
If you want to label 7-day old posts as new instead, just change (2*86400) to (7*86400). That’s it.

This is a nice think, I’ll try this one
great think.. I will perform it my website