Inserting a "last updated" value into your footer
Description
This snippet allows you to use custom tokens in your footer message to display, for example, a dynamic "last updated" date.
Step 1 of 2
In your template.php create the function mytheme_preprocess_page, where mytheme is the name of your theme.
<?php
function mytheme_preprocess_page(&$vars, $hook) {
// get date of most most recent change to a node
$last_updated = db_result(db_query('SELECT FROM_UNIXTIME(MAX(changed)) FROM {node}'));
// define replacement tokens for our footer message
$tokens = array(
'!last_updated' => $vars['last_updated'],
);
// replace tokens in footer_message
$vars['footer_message'] = strtr($vars['footer_message'], $tokens);
}
?>Step 2 of 2
Then, in admin >> Site information, you can put something like "Last updated: !last_updated" in the footer field, and voila! Now your pages will have a dynamic footer showing the last update to your site.
The next step
If you want to go a bit further, you can define new tokens - of pull in tokens from the token module.
If you want to be able to embed PHP in your footer, then simply put the following code in your mytheme_preprocess_page function. Use with caution though...
<?php
$var['footer_message'] = drupal_eval(variable_get(variable_get('site_footer', FALSE)));
?>
Inserting "last updated" time using Views
You can also achieve this same functionality by simply using a view.
Here are the steps to create the view:
1. Check the box to provide a block (when creating the view). You should also set to show 1 Node per block. Set the view type to list.
2. In the Fields section, add the field Node: Updated Time. You can set the Handler to anything you want.
3. In the Filters section, select Node Type and then highlight what node types you want to check updates for. (It's also a good idea to check that the node is published as well).
4. In the Sort Criteria, add the field: Node: Updated Time and order by Descending.
Then you can insert this block view you just created in any region in your theme.
