Hello,
Ok, but did you implement the code on all modules? They each have their own file and all of theme have to be modified: https://www.screencast.com/t/sAILJL8stu
Thank you!
Hi,
Try the code like this
– https://www.screencast.com/t/rnAo76A8dDkG
Then it should work properly
– https://www.screencast.com/t/y0FpQntGHN
<?php echo human_time_diff( get_the_time('U', $this->post->ID), current_time('timestamp') ) . ' ago'; ?>
It may further require some styling to align the time, that can be done with some CSS.
Thanks
Hi,
I don’t understand exactly what you want to modify. If it is the time format you can change the time parameters in the code
– https://codex.wordpress.org/Function_Reference/get_the_time
– https://codex.wordpress.org/Formatting_Date_and_Time
The current code works as mentioned here
– https://codex.wordpress.org/Function_Reference/human_time_diff
Thanks
Hi,
@wizimatic You could wrap the code in a div with a custom class, like this
– https://www.screencast.com/t/BR1BkgCP1TC
Then refer to that class and style the date as you want
– https://www.screencast.com/t/AeY3jqDq9fo8
– https://forum.tagdiv.com/create-custom-code-using-the-browsers-inspector/
Can i use your code <?php echo human_time_diff( get_the_time(‘U’, $this->post->ID), current_time(‘timestamp’) ) . ‘ ago’; ?> for post pages (single.php) sir?
I put
<?php echo human_time_diff( get_the_time(‘U’),
current_time(‘timestamp’) ) . ‘ ago’; ?>
on my mobile front page but i need the code to put on the single.php that will show timeago for individual posts.
just wondering about the difference between the two codes which is $this->post->ID
Also, There is a dash (-) inbetween the authors name and category name on my homepage(using the newspaper mobile theme), i dont know how to hide it and make the meta info closer to each other.
Also, how do i include the time ago on the featured posts.
my url is https://wizimatic.com (pls access from mobile to see)
The styling using “myclass” worked perfectly.
The modules displayed on the mobile front page are here
– https://www.screencast.com/t/M9XfBgdPcs
Edit them with the time format code if you want to. The single file for the mobile theme is this one, edit it like this
– https://www.screencast.com/t/TfONnKLv0
i used this code <?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’;}
?>
but the styling class didnt work the moment the posts is over a month. The date didnt align with other metas
Maybe move the other meta instead of the new time format
– https://www.screencast.com/t/Lu6RZgNDx
header .td-module-meta-info .td-post-author-name {
top:0;
}
Or do it the same with a div and class. For the mobile theme, CSS code has to be entered here
– https://www.screencast.com/t/CsHYYBlQFh7
That code works for me, posts within a month
– https://www.screencast.com/t/Ou41YeLbgd
Older posts – https://www.screencast.com/t/5p0PvZjvjq
How did you setup the styling ,what is happening exactly? Provide a link to the website where I can see this if possible.
You can check on mobile.. Here is a recent post, the meta information aligns properly, http://wizimatic.com/china-releases-3-year-plan-for-air-pollution-control/
Here is a long time post; https://wizimatic.com/infantino-wants-video-refs-for-2018-world-cup/
the post meta (date) doesnt align. I use the same div class for it. Here is the code that i am using, right in single.php
<div class=”classing”><?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’;}
?></div>
This is not valid – https://www.screencast.com/t/5nM9WmAP
Be sure to use px and not such a high value, with -15px it will be too high
– https://www.screencast.com/t/LfaC894drtm
In the other example a value like this would be best
– https://www.screencast.com/t/HPaQec5A
You could add divs individually, for each case, like this
– https://www.screencast.com/t/YEALpxfDW
Then style them differently if needed.
Okay thank you so much. That really helped. However the last problem I’m facing is, on my single posts (mobile theme) related posts are inheriting the date of the posts. That is, if the post has a time of 1hr ago, all related posts below the posts also have 1hr.
You can check using this post link below;
https://wizimatic.com/fresh-music-b-red-run-come-ft-cdq/
I tested your code, that is not happening for me
– https://www.screencast.com/t/vckRb9ml
– https://www.screencast.com/t/UYDsjbhq
Also an older post – https://www.screencast.com/t/TWev3wgE
– https://www.screencast.com/t/Ww3QVJZFRY
I used the same code with condition you provided, in the mobile theme single file
– https://www.screencast.com/t/xPyhiQ4nSs
Maybe double check your modification.
This is the code i am using on my single.php page (post page on mobile theme)
<?php
$time = human_time_diff(get_the_time(‘U’),
current_time(‘timestamp’));
$pos = strpos($time, ‘months’);
if ($pos>0) {echo ‘<div class=”classing”>’ . $td_mod_single->get_date ( show_stars_on_review, false) . ‘</div>’;}
else {echo ‘<div class=”classing1″>’. $time . ‘ ago’. ‘</div>’;}
?>
and its bringing same time for posts and related posts
Remove the code and return to default, see what happens. If there is no problem enter it again
<?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';}
?>
This is the same code I used and it works as shown above. Test and check all the other modifications made until now. test only with the mobile theme modification maybe, remove all others temporarily.
Maybe you modified the mobile theme modules
– https://www.screencast.com/t/Lz1RKpyiDf
The related articles module is module 1, check the modifications made there.
