Page 1 of 1

UDT - Last modified date and author name on page footer

Posted: Thu Mar 18, 2010 1:05 pm
by blast2007
I need to put on every page last modified date and full author name (First, Last).

I can't found similar post on forum so I wrote this small piece of code. Just create a new UDT (for example page_footer)

Code: Select all

function datetime($syntax,$datetime) {
    $year = substr($datetime,0,4);
    $month = substr($datetime,5,2);
    $day = substr($datetime,8,2);
    $hour = substr($datetime,11,2);
    $min = substr($datetime,14,2);
    $sec = substr($datetime,17,2);
   
    return date($syntax,mktime($hour,$min,$sec,$month,$day,$year));
}


global $gCms;
$db =& $gCms->GetDb();
$thisPage = $gCms->variables['page_name'];

$query = "SELECT " . cms_db_prefix() . "content.modified_date" ."," . cms_db_prefix() ."users.first_name" . "," . cms_db_prefix() ."users.last_name FROM " . cms_db_prefix()."content LEFT JOIN ". cms_db_prefix()."users ON " . cms_db_prefix() . "content.last_modified_by =". cms_db_prefix() ."users.user_id WHERE content_alias=" . "'". $thisPage . "'"  ;

$row = $db->GetRow($query);

$dbresult = $db->Execute( $query);
if (!$dbresult)
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
else
{
echo "<div class=\"small\">";
echo  "Last modified date: ". datetime("d/m/Y h:m:s",$row['modified_date']) ."<br />";
echo "by: ".  $row['first_name']. ' '. $row['last_name']  ;
echo "</div>";
}
Then put {page_footer} on your template just after {content} tag.

Hope it helps.
Regards
blast

Re: UDT - Last modified date and author name on page footer

Posted: Thu Mar 18, 2010 1:12 pm
by calguy1000
It never ceases to amaze me the amount of effort people will go to to not read documentation.

Re: UDT - Last modified date and author name on page footer

Posted: Thu Mar 18, 2010 5:34 pm
by Nullig
Yeah, you coulda just used the {modified_date} tag.

You can read all about it, and many other useful tags, in the Admin Panel under Extensions/Tags.

Nullig

Re: UDT - Last modified date and author name on page footer

Posted: Thu Mar 18, 2010 7:36 pm
by blast2007
I missed those tags. My bad!