开发者

Drupal Display Modified Date for Node

Is there a simple way in Drupal to display the last modified date for a node as part of the node.tpl.php f开发者_如何转开发ile?


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.


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.


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']));
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜