2011-09-27 67 views

回答

10

如果您在node.tpl.php文件中把這個代碼,它會顯示上次更改節點日期:

<?php 
echo format_date($node->changed); 
?> 

你想要它周圍的任何HTML。

+1

謝謝!似乎很簡單,但我很難在文檔中找到它... – caseyamcl

1
If you place below code in you node.tpl.php file - 

<?php 

    $node = node_load($nid); 
    echo $node->changed; 

?> 

你會得到時間戳,我認爲可以更改日期。

這裏$ tid文件中的$ nid表示當前節點ID,並且hook node_load()加載與節點id相關的所有信息。

+1

我不認爲你需要再次加載節點。 $ node對象應該在node.tpl.php中可用。 – nmc

+0

雅我發現答案後發現。但多虧了糾正代碼的性能。 –

+1

這並不重要,'node_load'的結果被緩存,因此通過重新加載節點只需要幾毫秒的時間。根據模塊的加載順序,實際上可能*必須*重新加載節點以獲取其完全加載的屬性 – Clive

1

無需編輯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'])); 
    } 
}