First, add the following code to the topic's functions. php file:
The code is as follows: |
Copy code |
Function timeago ($ ptime ){ $ Ptime = strtotime ($ ptime ); $ Etime = time ()-$ ptime; If ($ etime <1) return 'gang '; $ Interval = array ( 12*30*24*60*60 => 'years ago ('. date ('Y-m-D', $ ptime ).')', 30*24*60*60 => 'months ago ('. date ('M-D', $ ptime ).')', 7*24*60*60 => 'week before ('. date ('M-D', $ ptime ).')', 24*60*60 => 'Days ago ', 60*60 => 'hour ago ', 60 => 'minute ago ', 1 => 'seconds ago' ); Foreach ($ interval as $ secs => $ str ){ $ D = $ etime/$ secs; If ($ d> = 1 ){ $ R = round ($ d ); Return $ r. $ str; } }; } |
How to use the list page and article page:
Applicable
Index. php
Search. php
Tag. php
Single. php
Page. php
Author. php
Category. php
Replace the following with the display time? In the php code block:
The code is as follows: |
Copy code |
Echo 'published in'. timeago (get_gmt_from_date (get_the_time ('Y-m-d G: I: s '))); |
How to use the comment area:
Replace the following with the display time, which must be placed in the comment loop:
The code is as follows: |
Copy code |
Echo 'published on'. timeago ($ comment-> comment_date_gmt ); |
Others
Of course, you can also change the text in the function to meet your needs.
The format of the value transmitted by this function is "11:11:11", as long as the format complies with the line, but wp has a gmt time system, so the above usage is available
Then I found a file on the Internet that is also added to the functions. Php file.
// Display the time format of the newly added article before "several minutes"
The code is as follows: |
Copy code |
Function timeago (){ Global $ post; $ Date = $ post-> post_date; $ Time = get_post_time ('G', true, $ post ); $ Time_diff = time ()-$ time; If ($ time_diff> 0 & $ time_diff <24*60*60) $ Display = sprintf (_ ('% s ago'), human_time_diff ($ time )); Else $ Display = date (get_option ('date _ format'), strtotime ($ date )); Return $ display; } Add_filter ('The _ time', 'timeago '); // This is the call method. |