Is there a simple way in Drupal to display the last modified date for a node as part of the node.tpl.php file?
Asked
Active
Viewed 7,748 times
3 Answers
10
If you put this code in the node.tpl.php file it will show the date of the last change to the node:
<?php
echo format_date($node->changed);
?>
with whatever HTML you want around it.

Mark Cameron
- 2,359
- 2
- 24
- 29
-
1Thanks! Seems so simple, but I had a hard time finding it in the documentation... – caseyamcl Sep 27 '11 at 21:36
1
No need to edit node.tpl.php file. Use the following in template.php.
function sitetheme_preprocess_node(&$variables) {
$node = $variables['node'];
// Only add the revision information if the node is configured to display
if ($variables['display_submitted'] && ($node->revision_uid != $node->uid || $node->revision_timestamp != $node->created)) {
// Append the revision information to the submitted by text.
$revision_account = user_load($node->revision_uid);
$variables['revision_name'] = theme('username', array('account' => $revision_account));
$variables['revision_date'] = format_date($node->changed);
$variables['submitted'] .= t(' and last modified by !revision-name on !revision-date', array(
'!name' => $variables['name'], '!date' => $variables['date'], '!revision-name' => $variables['revision_name'], '!revision-date' => $variables['revision_date']));
}
}

user1988227
- 11
- 1
1
If you place below code in you node.tpl.php file -
<?php
$node = node_load($nid);
echo $node->changed;
?>
you will get the timestamp and i think that can be changed to date.
Here $nid in tpl file represent the current node id, and hook node_load() load the all information related to node id.

Vikas Naranje
- 2,350
- 5
- 30
- 40
-
1I don't think you need to load the node again. The $node object should be available in node.tpl.php. – nmc Sep 27 '11 at 11:34
-
ya i realized that after posting the answer. But thanks to correcting the code performance. – Vikas Naranje Sep 27 '11 at 11:52
-
1This doesn't really matter, results of `node_load` are cached so you only incur an extra couple of milliseconds by reloading the node. Depending on the module load order it might actually be *necessary* to reload the node to get at it's fully loaded properties – Clive Sep 27 '11 at 12:50
-
This works great in a view header. I have a view that displays the results of a data table. I needed to show when the information was last updated. The data table is updated when I upload a new file as an attachment to a specific node. – sho Jun 05 '13 at 00:31