Hi,
I have edited the functions to make use of the ‘time ago’ feature rather than a standard date format. I was successful in editing the comments to use <?php echo time_ago(); ?> and it works great.
However, I tried modifying the module files, but no changes take effect. Even if I delete the date section completely it will still show. How can I edit the modules and make it show the time ago?
Thanks,
Ok, so I attempted to use WordPress own variation:
<?php echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’; ?>
In place of the traditional module <?php echo $this->get_date();?> script.
The time ago timestamp gave a very wonky date. An article written today showed it as being ‘2 years ago’, which is obviously incorrect.
Any idea how I could get the time ago functioning on the modules instead of date?
Thanks!
Strange, should be working.. :S
Do get_date() and current_time(‘timestamp’) give you the correct date when you create a post?
Try to find the error by adding this to your php file:
echo '<script type="text/javascript">alert("' . get_date() . '")</script>';
echo '<script type="text/javascript">alert("' . current_time('timestamp') . '")</script>';
This will show a message box with the return value of both methods…
This works properly on the actual post page. However, it does not work in the meta section of the post when being shown via module block.
Any idea why the module would be showing incorrectly? Posts shown through the module from 2014 say ’45 years ago’ lol.
Thanks,
Ok, I have tested it…
Put this:
human_time_diff( $td_article_date_unix, (int) current_time(‘timestamp’))
In the get_date() method inside /includes/wp_booster/td_module.php
My get_date() method inside td_module.php:
Don’t copy/paste the example, because it could change operations, since I’ve customized a lot in my theme!)
function get_date($show_stars_on_review = true) {
$visibility_class = '';
if (td_util::get_option('tds_p_show_date') == 'hide') {
$visibility_class = ' td-visibility-hidden';
}
$buffy = '';
if (td_review::has_review($this->td_review) and $show_stars_on_review === true) {
//if review show stars
$buffy .= '<div class="entry-review-stars">';
$buffy .= td_review::render_stars($this->td_review);
$buffy .= '</div>';
} else {
if (td_util::get_option('tds_p_show_date') != 'hide') {
$td_article_date_unix = get_the_time('U', $this->post->ID);
$buffy .= '<div class="td-post-date">';
$buffy .= '<time itemprop="dateCreated" class="entry-date updated td-module-date' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" > ' . human_time_diff( $td_article_date_unix, (int) current_time(‘timestamp’)) . '</time>';
$buffy .= '<meta itemprop="interactionCount" content="UserComments:' . get_comments_number($this->post->ID) . '"/>';
$buffy .= '</div>';
}
}
return $buffy;
}