【发布时间】:2011-09-27 01:44:26
【问题描述】:
Drupal 中是否有一种简单的方法可以将节点的最后修改日期显示为 node.tpl.php 文件的一部分?
【问题讨论】:
标签: drupal drupal-7 drupal-theming
Drupal 中是否有一种简单的方法可以将节点的最后修改日期显示为 node.tpl.php 文件的一部分?
【问题讨论】:
标签: drupal drupal-7 drupal-theming
如果您将此代码放在 node.tpl.php 文件中,它将显示最后一次更改节点的日期:
<?php
echo format_date($node->changed);
?>
使用任何你想要的 HTML。
【讨论】:
If you place below code in you node.tpl.php file -
<?php
$node = node_load($nid);
echo $node->changed;
?>
您将获得时间戳,我认为可以将其更改为日期。
这里tpl文件中的$nid代表当前节点id,钩子node_load()加载所有与节点id相关的信息。
【讨论】:
node_load 的结果会被缓存,因此重新加载节点只会导致额外的几毫秒。根据模块加载顺序,实际上可能需要重新加载节点以获取其完全加载的属性
无需编辑 node.tpl.php 文件。在 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']));
}
}
【讨论】: