Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ericrallen/wp-relative-date-template-tag

Using relative dates in WordPress templates instead of the post_date
https://github.com/ericrallen/wp-relative-date-template-tag

Last synced: 5 days ago
JSON representation

Using relative dates in WordPress templates instead of the post_date

Awesome Lists containing this project

README

        

wp-relative-date-template-tag
=============================

Coming soon to the Wordpress Plug-in Repository.

Using relative dates in WordPress templates instead of the post_date

Adds functionality for 2 template tags: `the_relative_date()` and `get_the_relative_date()` to WordPress

These functions essentially work like the `the_date()` and `get_the_date()` template tags.

###Options

Each tag supports an array of completely optional parameters to allow developers to customize the returned value:

1. `period` - What to return relative time in, this will be de-pluralized automatically if necessary: (string) default is largest period that can be calulated >= 1 [acceptable values: 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years', 'decades', 'centuries', 'millenia'
2. `suffix` - What to append to the returned value, a space character [" "] will be prepended automatically: (string) default is 'ago'
3. `id` - Send a post ID to retrieve the relative date outside of a WordPress loop or to retrieve the relative date of another post inside a Wordpress loop: (int) default is `null`

###Examples

Display relative date for specific post as "days before now":

'weeks',
'suffix' => 'before now',
'id' => 22
);

//display relative date for post $id
$the_relative_date($args); ?>

Retrieve relative date for specific post as "seconds ago":

'seconds',
'id' => 22
);

//retrieve relative date for post in seconds
get_the_relative_date($args); ?>

Display relative date for current post as `n` time periods ago (where time periods is equal to the largest time period that can calculated for the current post with `n >= 1`):