I wanted to add a field in my website (in footer area), which can automatically display the "last updated" date.

I found the same question in SO but it is not working properly. While accessing some pages, I can see this field as blank with follow errors-

Notice: Undefined variable: node in include() (line 207 of O:\xampp\htdocs\rutag\sites\all\themes\skeletontheme\templates\page.tpl.php).
Notice: Trying to get property of non-object in include() (line 207 of O:\xampp\htdocs\rutag\sites\all\themes\skeletontheme\templates\page.tpl.php).

By saying "Last Updated at", I mean to say that the last date on which admin has updated (published/modified any content) the website.

  • Could you clarify what "last updated" means to you? Is that the last time a content node was added? Updated? Certain content types only? RSS feeds aggregated? User logged in? Comment added? – Graham Mar 31 '14 at 17:53
  • Depending on your content, you could very easily just select from node order by date and get the latest changed date. – Steven Mar 31 '14 at 18:00
  • @Graham: Sorry for the ambiguity raised here. I have updated my question. You can now read it again. – Ravi Joshi Apr 1 '14 at 15:00
  • @Steven: I am new to drupal. I am not getting exactly whatever you are saying. Can you please be more specific? Also you can read my edit in the question. Also please let me know if there exist any module for the same. – Ravi Joshi Apr 1 '14 at 15:01

Not all page types have a a $node object associated (the user page, for one does not). You can get rid of the error message that says:

Notice: Undefined variable: node

by wrapping the call to format_date in an if-statement like this:

if (isset($node->changed)) {
  print "Last modified date: " . format_date($node->changed);
| improve this answer | |
  • Hi Gisle, As I said earlier, the above php code is NOT WORKING ONLY in some pages. I can see the "Last Modified date: " at home page but not in user page :( If required, you can have a look for theme files here – Ravi Joshi Apr 1 '14 at 16:16
  • The poster notes why it only works on node pages. Reread. – Kevin Jun 27 '17 at 15:44
  • You cannot add a field in the footer. You have to create a custom block/pane to print the last updated date/time. Use below code to get the last updated node and then print it in a block after that you can assign this block in your footer region. – Mohammad Anwar Jan 4 '19 at 20:27
  • $format2 = 'g:i a'; $result2 = db_query("SELECT title, changed FROM {node} WHERE status = 1 ORDER BY changed DESC"); if ($node = db_fetch_object($result2)) { $output2 .= date($format2, $node->changed); } print $output2; – Mohammad Anwar Jan 4 '19 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.