Drupal Display Modified Date for Node

早过忘川 提交于 2019-12-12 18:55:59

问题


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


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/7563340/drupal-display-modified-date-for-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!