Date Last Edited

07-27-2010

Post a date on a page that updates whenever that page is edited. 

We wanted to post a date on a page that would update whenever that page was edited.  We found a lot of possibilites in the C5 forums, but none worked quite right.

getSiteLastEdit() would post a date when any page on the site was edited, not just the single page.

getCollectionDatePublic()  Would return the date the page was first created or set to be public, but not the date when the page was updated.

cDateModified in the database only gave us a new date if we changed page types, not if we edited a block.

What we really wanted to do was display the last date any block on a page was updated, not the page itself.  Here's a snippet of code that uses getBlocks() and sorts by getBlockDateLastModified().  We only look at blocks in the Main area getBlocks('Main'), you can look at the whole page with getBlocks() or the sidebar with getBlocks('Sidebar')

// Load Date Helper
$date = Loader::helper("date");
 
// You may need to define $c
global $c;
 
// Get Blocks in Main area
foreach($c->getBlocks('Main') as $b) {
   $bDate[$i] = $b->getBlockDateLastModified();
   $i ++;
}
 
// Reverse Sort Date Array
rsort( $bDate );
 
//Echo Date and Time Page last Edited
echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s');
 

 

Information provided here has been compiled from Emails, Documentation and the Concrete5 Support Forums.   Examples of PHP, HTML and CSS code displayed on these pages may not be fully functional and may require to be used with other components.  Information here is provided as examples without warranty of any kind.  Weblicating.com has no direct affiliation with Concrete5 CMS Inc.  Thanks to everyone in the C5 community who has provided information for these pages.