Created
August 8, 2012 00:22
-
-
Save RalfAlbert/3290861 to your computer and use it in GitHub Desktop.
Date of last modification if at least one day later than the post creation 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 | |
/** | |
* Date of last modification if at least one day later than the post creation date. | |
* | |
* @author Thomas Scholz | |
* @param string $template Parsed with sprintf(). Must contain a '%s'. | |
* @param string|int $time_diff Time difference as string for strtotime() or integer as seconds | |
* @return string|void | |
*/ | |
function t5_post_last_mode( $template = '%s', $time_diff ) | |
{ | |
if ( empty( $time_diff ) ) | |
$time_diff = 86400; // 86400 seconds == 1 day | |
// UINX time stamps in seconds: | |
$changed = get_post_modified_time( 'U' ); | |
if ( is_string( $time_diff ) ) | |
{ | |
$made = strtotime( $time_diff, get_the_date( 'U' ) ); | |
$delta = 0; | |
} else | |
{ | |
$made = get_the_date( 'U' ); | |
$delta = &$time_diff; | |
} | |
if ( ( $changed - $made ) > $delta ) | |
{ | |
// readable formatted date | |
$human_last_mod = get_post_modified_time( | |
get_option( 'date_format' ), | |
FALSE, // GMT | |
NULL, // Post | |
TRUE // translate | |
); | |
return sprintf( $template, $human_last_mod ); | |
} | |
} | |
print t5_post_last_mode( 'Last modified: %s', '2 hour' ); | |
print t5_post_last_mode( 'Last modified: %s', 86400 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment