Drupal Display Modified Date for Node

2019-07-21 14:07发布

Is there a simple way in Drupal to display the last modified date for a node as part of the node.tpl.php file?

3条回答
戒情不戒烟
2楼-- · 2019-07-21 14:55

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.

查看更多
狗以群分
3楼-- · 2019-07-21 14:57

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']));
  }
}
查看更多
倾城 Initia
4楼-- · 2019-07-21 15:00
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.

查看更多
登录 后发表回答