Getting & Giving Support
- Ref. - PHPDoc
Wolf CMS books section
To display the date of the page use this code:
<?php echo $this->date(); ?>
If you want to change the format of the date, you can pass it as the first parameter of the method like this:
<?php echo $this->date('%A, %e %B %Y'); ?>
The default date returned is the page’s creation date. If you want to display the last updated time of this page do it like this:
<?php echo $this->date('%a, %e %b %Y', 'updated'); ?>
Other values that can be used instead of
- created — (default) which returns the date the page was initially stored in the database, no matter what “Status” it had; and
- published — which returns the date the page was first saved with the “Status” set to “Published”
For more information about the date format, check this site: http://php.net/strftime
On Windows, and rarely in other settings, the use of %e may prevent any date appearing! In this case, use %d in its place. (See PHP Bugs for more information.) A work-around is given below.
Set the locale to your language using the setlocale PHP function. Put this string at the top of your layout:
<?php setlocale(LC_ALL, 'fr_CA.utf8'); ?>
Note: for different languages in the admin/backend, use
Administration > Settings for default. Languages can also be set for each user in the
Users > [Username] settings.
In the note above, users were warned that in Windows and some other environments, use of the %e parameter (day-of-the-month number with no leading zeros) can break the output. The solution is to use the reliable %d parameter instead, which gives day numbers less than 10 with a leading 0.
If it is important to have the date in the form “6 August 2009” rather than “06 August 2009”, you can use this work-around:
<?php echo $this->date('%#d %b %Y'); ?>
If that code does not produce the desired result, this more verbose method should work:
<?php $day = ltrim($this->date('%d'), '0'); echo $this->date("$day %b %Y"); ?>
Both versions remove the leading zero, where present.