Souris
Souris

Reputation: 1

Drupal 7, how to add a "last updated" function on my site?

I wish to add a "Last updated" on my web site (a text automatically showing when my site's content was last up dated).

I found some answers on Drupal forum, unfortunately they all concern Drupal 6 and I simply couldn't get them to work on Drupal 7...

Since I know about nothing about PHP, and I belive it requires to add some PHP code, thank you very much if the answer could be "as simple as possible", and very "step by step" :o)

Thanks for any help!

Upvotes: 0

Views: 2406

Answers (3)

Free Radical
Free Radical

Reputation: 2072

Not all template files always have a $node object in scope (e.g. page.tpl.php when used to render the user page does not).

If, for instance, you want to the "Last modified date" line into page.tpl.php to have it the page footer, you need to make sure that you only call format_date when there is a $node object in scope.

This is how this should look like for Drupal 7:

<?php
if (isset($node->changed)) {
  print "Last modified date: " . format_date($node->changed);
}
?>

Upvotes: 0

K.Webb
K.Webb

Reputation: 11

Based on Muhammad's answer I was able to get this to work in Drupal 6. I just needed to modify a little.

<?php print "Last modified date: " . format_date($node->changed, $type = 'small'); ?>

Upvotes: 1

Muhammad Reda
Muhammad Reda

Reputation: 27023

You can use the node.tpl.php template and use the following line

<?php
    print "Last modified date: " . format_date($node->changed, "short");
?>

Hope this helps... Muhammad.

Upvotes: 0

Related Questions