I would like to add "new" icon on node view page of some content type for a predefined time frame after the node content is created or updated. For example, I would like to display "new" icon on the top of node view page for 2 weeks after the node content was saved. I found this for Views but need it for node page. Is there anyway to achieve this?


You can do this at least two ways:

1) Edit your theme's node.tpl.php to include some PHP code that compares the current date and the node creation or modification date, and, if it's within the predefined timeframe, prints that "new" icon wherever you want it, or,

2) Create a preprocess_node() hook in either a custom module or in your theme that sets a variable that can be used in your node.tpl.php file for the same purpose.


A quick (but verbose for self-commenting purposes) preprocess() hook in your template.php file could look something like this:

function phptemplate_preprocess_node(&$vars) {


  $two_weeks_ago = time() - (14 * 24 * 60 * 60);


  if ($node_creation_time >= $two_weeks_ago || $node_changed_time >= $two_weeks_ago) {
    $this_node_is_new="THIS NODE IS NEW!";



This would provide a $this_node_is_new variable in your node.tpl.php template file(s) when the node was created or modified within the last two weeks.

  • Thanks for your quick response. Unfortunately I'm not a coder and these methods are over my head. I would greatly appreciate if you have the snippet..
    – chinita7
    Dec 21 '11 at 9:09
  • I just tried your code and it works perfectly! This is exactly what I needed. Thanks a lot!
    – chinita7
    Dec 22 '11 at 3:52
  • You're quite welcome!
    – Jimajamma
    Dec 22 '11 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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