General
Getting Support
Administration
Design
Wolf Reference
Plugin Development
Core Development
- Design documents
- Working guidelines
- References
Press, Graphics and Translations
Wolf CMS books section
display the date of the page
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 updated are:
- 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.
How to translate every date in your layout
Set the locale to your language with the setlocale PHP function:
<?php setlocale(LC_ALL, 'fr_CA.utf8'); ?>
For more information about this function check this site: http://php.net/setlocale
Setlocale for different frontend/backend language
If you would like to keep your admin (backend) in English, and want your frontend to show some special characters (e.g. in Croatian - š, đ, ž, ć, č), the easiest way to do this is to put code:
<?php setlocale(LC_ALL, 'hr_HR.utf8'); ?>
on first line in your default Layout.
Work-around for the %e problem
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.
