Adds template tags to your wordpress blog that lets you show relative time strings,
such as “3 months and 2 days” or “4 months, 10 hours and 2 minutes”.
Unlike other algorithms used to calculate relative time, this plugin uses an algorithm based
on written substraction and therefore the calculated relative time is synchronous to the gregorian
Example: Let’s assume todays date were “2010-03-01” and the post date were “2010-02-01“. The
result of this plugin’s calculation would be “1 month“.
Currently only englisch and german localizations are available. But maybe you can help me
translate to other languages. I will gladly add them. (see “FAQ” for more details)
The following template tags are available
- the_date_relative / get_the_date_relative
- the_modified_date_relative / get_the_modified_date_relative
- comment_date_relative / get_comment_date_relative
Additionally there are two filter hooks available
Please see the “Other Notes”
tab for more information about the usage.
Du kannst auch auf deutsch lesen.
This is a BETA release
So, if something is not working as expected or you get others errors or you encounter incompatibilities to other
plugins – please report them to me so I can fix and improve my plugin.
All template tags accepts one optional parameter which specifies how many
relative time string parts should be in the string. This parameter must be
an integer between 1 and 7 inclusively.
The default value is 2.
To prevent strings like “1 year, 3 hours and 2 minutes, parts that have the value 0
and all following parts are stripped from the string, regardless of the value of
the optional parameter.
“1 year”, “3 days”
“1 year, 2 months and 4 weeks”, “12 days, 3 hours and 37 minutes”, “4 days”
displays the relative post date string
<?php the_date_relative($parts) ?>
gets the relative post date string
<?php $rel = get_the_date_relative($parts) ?>
displays the relative post modified date string
<?php the_modified_date_relative($parts) ?>
gets the relative post modified date string
<?php $rel = get_the_modified_date_relative($parts) ?>
displays the relative comment date string
<?php comment_date_relative($parts) ?>
gets the relative comment date string
<?php $rel = get_comment_date_relative($parts) ?>
If, for whatever reason, you have a date which is not covered by the tags above, that you
want to show as a relative string, you can use the following functions:
<?php tirt_get_string($date, $parts) ?>
gets a relative date string
- $date (string) the date to show relative in mysql DateTime format
- $parts (int) (optional) How many parts to show maximal (Default: 2)
<?php tirt_get_array($date) ?>
gets relative date parts as array in the form:
‘year’ => ,
‘month’ => ,
‘week’ => ,
‘day’ => ,
‘hour’ => ,
‘minute’ => ,
- $date (string) the date to get the relative parts in mysql DateTime format
On general information how to use filter hooks, please see the
applied to the date array at the end of tirt_get_array.
Can be used to modify the values of the array.
NOTE: The filter using this hook MUST return an array with the same
keys as the input array.
applied to the relative time string.
Can be used to i.e append or prepend text to the string, If you do not want
to do that on every occurence of the template tag in your theme files.
- Upload the .zip file to your plugins folder and unzip
- Activate the plugin through the plugin management admin interface
- Add the template tags to your theme files (see “Usage”)
- (Optional) Uses the filter hooks to modify the output without touching the
There are no settings for this plugin, it will work straight away.
- How do I translate to other languages?
Just take the “tirt.pot” file located in the subdirectory “translations” under the plugin’s root directory and add
the translated string in the “msgstr” line between the ‘”‘.
Save the edited file as “tirt-[langCode].po” and convert it to a .mo file with gettext.
Or use poedit: Load the tirt.pot file as new catalog, translate the strings and
save it as “tirt-[langCode].po”, poedit will automatically create a .mo file.
[langCode] is the language code, such as “en_EN” or “de_DE”.
Contributors & Developers
“[TiSiE] RelativeTime” is open source software. The following people have contributed to this plugin.Contributors
Interested in development?
- fixed: The date was not validated. (see upgrade notice)
- new: Error handling. Now uses WP_Error objects to reflect errors.
- new: Two filter hooks: tirt_get_string and tirt_get_array