Customized lastupdate

If you want to display the names of the weekday and the Month of the last update of your website, e.g. “Wednesday, October 5th, 2011”, you can set

$tx['lastupdate']['dateformat']="l, F jS, Y";

But that works for english dates only. A good alternative is to use the Last Update plugin, which will work even for multi-language installations. But if you need it only for one language, you can use the following function:

function custom_lastupdate($br = NULL, $hour = NULL) {
    global $pth, $tx;
    // translate the following 5 lines according to your needs
    $weekday_names = array('Sunday' , 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    $month_names = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    $day_suffix = array('st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
	    'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
	    'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th');
    $timestamp = filemtime($pth['file']['content']);
    $day = date('j', $timestamp);
    $weekday = date('', $timestamp);
    $month = date('n', $timestamp);
    $year = date('Y', $timestamp);
    // adjust the actual format according to your needs
    $datestring = "{$weekday_names[$day]}, {$month_names[$month]} {$day}{$day_suffix[$day]}, {$year}";
    $timestring = date('H:i:s', $timestamp);
    return $tx['lastupdate']['text'].':'.(isset($br) ? tag('br') : ' ').$datestring.' '.$timestring;

Just put it into cmsimple/userfuncs.php or cmsimple/functions.php, translate and adjust it according to your needs and change the call to lastupdate() in your template to custom_lastupdate().

Christoph M. Becker

tips_and_tricks/lastupdate_customized.txt · Last modified: 2018/04/05 14:48 (external edit)
Webdesign: NMuD = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0