I have some nodes I update frequently, but in content pane I can see the posting date of node.
How can I make Drupal 7 show the date of the latest edit, instead of the posting date?
You can use hook_node_view to add the change date content like this:
/**
* Implement hook_node_view()
*/
function youmodule_node_view($node, $view_mode, $langcode) {
$changde_date = date('l jS \of F Y h:i:s A', $node->changed);
$node->content['body'][0]['#markup'] = "<div class='changed-date'>$changde_date</div>" . $node->content['body'][0]['#markup'];
}
I would tackle this in a template_preprocess_node, either in a module or in your theme.
function mytheme_preprocess_node (&$variables)
{
$variables['date'] = format_date($variables['node']->changed);
}
Depending on your node template, you may also want to do something like
function mytheme_preprocess_node (&$variables)
{
$variables['date'] = format_date($variables['node']->changed);
if (variable_get('node_submitted_' . $variables['node']->type, TRUE)) {
$variables['display_submitted'] = TRUE;
$variables['submitted'] = t('Edited by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
$variables['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : '';
} else {
$variables['display_submitted'] = FALSE;
$variables['submitted'] = '';
$variables['user_picture'] = '';
}
}
so that your new $date
gets used in $submitted
, due to the preproccess/process order.
You can also play around with variants. For example, you could have both created and last edited dates; you would juust need to set up the variables in the preprocess function, and then use them in your node.tpl.php
.
print $var;
where you want it placed correct?
Commented
Jan 12, 2012 at 21:01