Hi, hope you are well.
I’m trying to install the meks time ago feature but it is not working. Kindly help. The plugin developer says that the theme is using a slightly different framework and it is reallyr urgent.
Regards.
Hi, I amanged to get the time ago feature using the code below
<?php $post_id = $this->post->ID;?>
<?php echo human_time_diff( get_the_time(‘U’, $post_id), current_time(‘timestamp’) ) . ‘ ago’; ?>
is there any possible way of returning to the actual date once the time ago counter hits 24 hours? i.e. once I add a new post, it will read an hour ago, 3 hours ago and once it hits 24hrs ago or a day ago, it should read 21st February 2018 or whichever date format is selected on the backend etc.
Hello,
In order to have that sort of implementation you will need to add extra checks to your code.
Here is an example:
<?php
$time = human_time_diff(get_the_time('U'), current_time('timestamp'));
$pos = strpos($time, 'months');
if ($pos>0) {
echo $td_mod_single->get_date(false);;
}
else{echo $time . ' ago';}
?>
I checked for ‘months’ and if the string is found, it will revert back to the original date. You can also check for days or even years
I hope this helps.
Thanks
Hi,
I tried implementing the above but the site frontend disappearedand the code also has some errors. Kindly help.
The code works perfectly fine on my end. Here is how I implemented it: https://www.screencast.com/t/sm5WnyfKYd7
Simply replace this code with it: https://www.screencast.com/t/BcAMXD5E
Thanks.
Hello,
If you change the single files, you will affect the posts, not pages.
Here is an example for pages: https://forum.tagdiv.com/topic/changing-the-date-to-x-time-ago/
Thank you!
Hi there,
Looking to get this work for the flex modules.
I figured out to use this part of code to get the ‘time ago’ function working. (Your example doesn’t work on the flex modules.)
<?php $post_id = $this->post->ID;?>
<?php echo human_time_diff( get_the_time(‘U’, $post_id), current_time(‘timestamp’) ) . ‘ ago’; ?>
But what needs to be added to show the ‘default date’ format if the post is older than 24 hours?
Also how to make the ‘element settings’ work on this adjustment? When I replace the code, the date is shown on all used modules, even if date is ‘not shown’?
Hope you can help me out.
Thanks in advance,
Webagent05
-
This reply was modified 7 years by
Webagent05.
Hi,
Maybe try the solution from this topic – https://forum.tagdiv.com/topic/implementing-the-time-ago/
I remember it worked at the time. In the latest update we introduced a last modified option for the modules – http://prntscr.com/mujoi7
But a time ago would have to be implemented manually, there is no setting for it at the moment.
Thanks
