WordPress.org

Ready to get started?Download WordPress

Plugin Directory

!This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

[TiSiE] RelativeTime

Adds template tags to your wordpress blog to let you show dates and times in a relative way.

Usage

General

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.

Examples: - the_date_relative(1)

"1 year", "3 days"

  • the_date_relative(3)

    "1 year, 2 months and 4 weeks", "12 days, 3 hours and 37 minutes", "4 days"

Template Tags

  • the_date_relative

    displays the relative post date string

    Usage: <?php the_date_relative($parts) ?>

  • get_the_date_relative

    gets the relative post date string

    Usage: <?php $rel = get_the_date_relative($parts) ?>

  • the_modified_date_relative

    displays the relative post modified date string

    Usage: <?php the_modified_date_relative($parts) ?>

  • get_the_modified_date_relative

    gets the relative post modified date string

    Usage: <?php $rel = get_the_modified_date_relative($parts) ?>

  • comment_date_relative

    displays the relative comment date string

    Usage: <?php comment_date_relative($parts) ?>

  • get_comment_date_relative

    gets the relative comment date string

    Usage: <?php $rel = get_comment_date_relative($parts) ?>

Additional Functions

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

    Parameters:

    • $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:
    array( 'year' => <value>, 'month' => <value>, 'week' => <value>, 'day' => <value>, 'hour' => <value>, 'minute' => <value>, 'second' => <value> );

    Parameters:

    • $date (string) the date to get the relative parts in mysql DateTime format

Filter Hooks

On general information how to use filter hooks, please see the Funtion Reference

  • tirt_get_array

    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.

  • tirt_get_string

    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.

Requires: 2.9 or higher
Compatible up to: 3.0.5
Last Updated: 2011-1-11
Downloads: 541

Ratings

5 stars
5 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1
100,1,1
100,1,1