Created
April 22, 2011 02:27
-
-
Save mattrude/935898 to your computer and use it in GitHub Desktop.
WordPress Plugin to display the time since a entered date.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Matt Rude <matt@mattrude.com> - 1 Nov 2009 | |
This shortcode displays the years since the date provided. | |
To use this shortcode, add some text to a post or page simmiler to: | |
[ts date='1983-09-02'] | |
The date format is YYYY-MM-DD | |
*/ | |
function mdr_timesince($atts, $content = null) { | |
extract(shortcode_atts(array("date" => ''), $atts)); | |
if(empty($date)) { | |
return "<br /><br />************No date provided************<br /><br />"; | |
} | |
$mdr_unix_date = strtotime($date); | |
$mdr_time_difference = time() - $mdr_unix_date ; | |
$years = floor($mdr_time_difference / 31556926 ); | |
$num_years_since = $years; | |
return $num_years_since; | |
} | |
add_shortcode('ts', 'mdr_timesince'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment