Skip to content

Instantly share code, notes, and snippets.

@trk
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trk/a9d7e01ecfa6e40b65bc to your computer and use it in GitHub Desktop.
Save trk/a9d7e01ecfa6e40b65bc to your computer and use it in GitHub Desktop.
/**
* Get last modified page modified date from given $id, $parent_id, $templates_id or from all
*
* @param bool $id
* @param bool $parent_id
* @param bool $templates_id
* @return mixed|string
*/
function getLastModified($id=false, $parent_id=false, $templates_id=false) {
if(!is_null($id)) {
$where = "";
if(is_bool($id) != true) {
$where = " WHERE";
$where .= ($parent_id) ? " parent_id = {$id}" : " id={$id}";
$where .= ($templates_id) ? " AND templates_id = {$templates_id}" : "";
}
$results = wire('db')->query("SELECT MAX(modified) as modified FROM pages{$where}");
if($results->num_rows > 0) {
$result = $results->fetch_assoc();
$search = array(' ', '-', ':');
$replace = array('', '', '');
return str_replace($search, $replace, $result['modified']);
}
}
return "";
}
@trk
Copy link
Author

trk commented Apr 30, 2015

Added $templates_id for template filtering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment