Skip to content

Instantly share code, notes, and snippets.

@kvnm
Created April 3, 2014 20:14
Show Gist options
  • Save kvnm/9962002 to your computer and use it in GitHub Desktop.
Save kvnm/9962002 to your computer and use it in GitHub Desktop.
Find the last time drupal content of a particular content type or list of content types was updated (without views). Sometimes people like this kind of thing, apparently.
<?php
/**
* Returns a single "Last Updated" date.
*
* $types -- an array of content type machine names. Defaults to 'page'.
*/
function custom_last_updated($types = array('page')) {
$query = db_select('node', 'n');
$query
->condition('type', $types, 'IN')
->condition('status', 1, '=')
->fields('n', array('changed'))
->orderBy('changed', 'DESC')
->range(0, 1);
$result = $query->execute()->fetchField();
$last_changed = '<div class="last-updated">Last Updated: ' . format_date($result, 'custom', 'l, F jS, Y') . '</div>';
return $last_changed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment