Plugin Directory

wp-days-ago

Displays the number of years, days, hours and minutes since a post or a page was published in the same format as Facebook, Twitter etc.

  1. Download the plugin.
  2. Unzip the contents of the downloaded file to the /wp-content/plugins/ directory of your WordPress installation.
  3. Log in to your WordPress dashboard and activate the wp_days_ago plugin that should now be visible in the list.
  4. You can now insert <? wp_days_ago(); ?> (or <? wp_days_ago_ajax(); ?>) anywhere in The Loop in your WordPress theme.
  5. Optionally, you can use <? wp_days_ago(1); ?> (or <? wp_days_ago_ajax(1); ?>) instead to turn off the fine grained option (see the changelog). This will make the plugin behave like the 1.x version.

Plugin URL: http://www.vegard.net/archives/3781/

Support for cache plugins

Since version 2.5, wp-days-ago supports cache plugins by making an AJAX call from the client to correctly display the time since a post or page was published.

To achieve this, use the wp_days_ago_ajax function instead of wp_days_ago. Please note that the wp_days_ago_ajax function does not support the $texts parameter. Other than that, it behaves the same way as the wp_days_ago method. Please see below for details.

If you decide to use the wp_days_ago_ajax function, you should be aware of this: The way WordPress handles AJAX functions is less than efficient and if you have a lot of views on your site you will experience a higher load on the system. Please see the usage documentation for the wp_days_ago_ajax method for details.

Usage for non-cached sites

<?php wp_days_ago( $mode, $prepend, $append, $texts, $showDateAfter, $showDateFormat); ?>

Parameters

$mode (int) (optional) Use any value larger than 0 to turn off displaying minutes and hours and instead fall back to "Today" for everything published less than 24 hours ago. Default value is 0.

$prepend (string) (optional) This text will be prepended to the plugin's default output. Default value is "" (empty string).

$append (string) (optional) This text will be appended to the plugin's default output. Default value is "" (empty string).

$texts (array) (optional) This array allows you to change the texts used by the plugin. This will, for instance, allow you to translate the output to your language. Use null as the parameter value to force the plugin to use the default string array: array("Today", "Yesterday", "One week ago", "days ago", "year", "years", "ago", "day ago", "days ago", "Just now", "One minute ago", "minutes ago", "1 hour ago", "hours ago", "Some time in the future").

$showDateAfter (int) (optional) The number of seconds since a post or page was published before the plugin falls back to showing the actual date and time the post or page was published. The default is -1 seconds, i.e. the feature is turned off by default.

$showDateFormat (string) (optional) The format the plugin should use to display the date and time a post or page was published if the number of seconds configured in the showDateAfter parameter has been reached. The default behaviour is to use the date and time formats configured in WordPress. See Formatting Date and Time for other time and date formats if you want to override the configured formats.

Usage for cached sites

<?php wp_days_ago_ajax( $mode, $prepend, $append, $threshold, $showDateAfter, $showDateFormat); ?>

Parameters

$mode (int) (optional) Use any value larger than 0 to turn off displaying minutes and hours and instead fall back to "Today" for everything published less than 24 hours ago. Default value is 0.

$prepend (string) (optional) This text will be prepended to the plugin's default output. Default value is "" (empty string).

$append (string) (optional) This text will be appended to the plugin's default output. Default value is "" (empty string).

$threshold (int) (optional) The number of seconds since a post or page was published before the AJAX method should revert to serving date information without using AJAX (in the same way as the wp_days_ago method). The default value is 86400 (one day). The value should match the configured invalidation threshold of your cache plugin.

$showDateAfter (int) (optional) The number of seconds since a post or page was published before the plugin falls back to showing the actual date and time the post or page was published. The default is -1 seconds, i.e. the feature is turned off by default.

$showDateFormat (string) (optional) The format the plugin should use to display the date and time a post or page was published if the number of seconds configured in the showDateAfter parameter has been reached. The default behaviour is to use the date and time formats configured in WordPress. See Formatting Date and Time for other time and date formats if you want to override the configured formats.

The output from wp_days_ago_ajax will be enclosed in a span-element that uses the class "wp_days_ago".

Requires: 2.1 or higher
Compatible up to: 3.5.1
Last Updated: 2013-2-9
Downloads: 4,043

Ratings

5 stars
5 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

1 person says it works.
0 people say it's broken.

100,1,1
100,1,1
100,1,1
100,1,1
100,1,1
100,1,1
100,1,1
100,1,1 100,1,1 100,1,1
100,1,1 100,1,1 100,1,1
100,1,1
100,2,2
100,1,1 100,1,1
100,1,1
100,1,1
100,1,1 100,1,1 100,1,1 100,1,1
100,1,1
100,1,1 100,1,1