Today, when looking at the Ali Baixiu's website, I found that there is a more intimate function, as shown below, the date of the article release can be different with the freshness of the article, such as today's published articles, the release time is specific to a certain minute, and yesterday's published articles, directly display yesterday, and then further, it will be directly display the date.
Personally feel that this way of user experience is very good, so a simple study of the realization of the method. The realization is actually relatively simple, first get the article release time, and then get the current time, compare the two times, and then determine the article release time display method, the code is as follows.
<?php if($days
Directly copy the above code to the place you need to display on it, of course, we can also write the above function into a function, so that the call will not have to repeat so much code, the template will also look a little more concise.
Function to adjust the time display according to the freshness of the article
A partner asked how to write the above function as a function of the way, well, for your convenience, directly written as a function posted.