In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to optimize the time display of articles and comments in WordPress, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The principle of improved time display
Very simply, through a built-in function of WordPress to deal with the current time and the time difference between articles and comments, showing that there are X minutes, X hours, and X days from now.
Usage:
Description:
Judge the difference between the two time markers.
Returns the time difference between the $from and $to time variables in human-readable formats such as "1 hour", "5 minutes", and "two days".
It is also easy to understand from English: from to to. This sentence is very useless, . )
Implementation of prototype improvement
/ / just change the function displayed by your comment time to the following
All the dates calculate the time difference, isn't it violent?
The implementation of the primary version
Simply add a judgment: if the comment time is not longer than one day, the XX hour will be displayed, and if more than one day, the original date will be displayed.
Isn't that more humane? Readers can't always count on their fingers to figure out what it was 38 days ago, right? Ha ha!
Code:
/ / just change the function displayed by your comment time to the following
So can we enhance it a little bit?
Why is it enhanced?
Well, because I am more serious, I think the Chinese display date is not good-looking, which affects my typesetting. I like to show the date in English, while the Chinese version of WordPress really has no dead corner (the Chinese is really careful). If we directly use the human_time_diff function to output, the Chinese version of WordPress will show all the results in Chinese before XX hours and XXD, which is likely to affect our typesetting. And there are neither hooks nor an unChinese parameter in this human_time_diff function, so there are only two ways to display English:
Directly modify the human_time_diff function, so that the Chinese invalid, this is too violent, and later upgrade and then go in to change, the family does not like.
Rewrite your own human_time_diff function, bypassing Sinicization.
The following code is forcefully inserted into function.php:
/ / the day hour min of the original function is all lowercase, / / I change the initials of these three words to uppercase, that is, Day Hour Min can avoid Sinicization, you know? If (! Function_exists ('xz_time_diff'): function xz_time_diff ($from, $to =') {if (empty ($to)) $to = time (); $diff = (int) abs ($to-$from); if ($diff)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 244
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.