BPOVIA Website Design

Icon

Provides High-quality Web Design And Maintenance Service In The World

WordPress Posts relative time display and comment

WordPress theme functions.php first insert the following function:

function time_diff ($ time_type) {
    
switch ($ time_type) {
        
case 'comment': / / If it is time for comments
            
$ Time_diff = current_time ('timestamp') – get_comment_time ('U');
            
if ($ time_diff <= 86400) / / 24 hours
                
echo human_time_diff (get_comment_time ('U'), current_time ('timestamp')).' before'; / / display format before it
            
else
                
printf (__('% 1 $ s at% 2 $ s'), get_comment_date (), get_comment_time ()); / / display format X in X time on X day it
            
break;
        
case 'post'; / / If this is the log of the time
            
$ Time_diff = current_time ('timestamp') – get_the_time ('U');
            
if ($ time_diff <= 86400)
                
echo human_time_diff (get_the_time ('U'), current_time ('timestamp'));
            
else
                
the_time ('Y.m.d');
            
break;
    
}
}

Then, let's change the comments section of the time, find the topic in the comments function of time, generally not in the callback function in functions.php in the comments, that is directly written in comments.php where, of course, does not rule out unconventional themes, such as that my comments only time I hid in a corner they can find. No matter so much, in short, is to find a function similar to the following:
<? Php printf (__('% 1 $ s at% 2 $ s'), get_comment_date (), get_comment_time ());?>

Replace it:
<? Php time_diff ($ time_type = 'comment');?>

Similarly, let us modify the format of the log relative release time, usually in the WordPress theme single.php and index.php there will be a function of time in which to find the following functions:
<? Php the_time ('Y.m.d');?>

Then replace it:
<? Php time_diff ($ time_type = 'post');?>

We're Done, you can see the effects of time and site reviews blog publishing time, leave your comments quickly to experience it.

BPOVIA All Rights Reserved
Maintained by BPOVIA Web Design Team

Category: website, WordPress

Tagged: ,

Leave a Reply