Advertisement
pusatdata

Menampilkan Data Update Terbaru pada Post

Mar 23rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. CARA I
  2. ============
  3. function.php themes:
  4.  
  5. function wpb_last_updated_date( $content ) {
  6. $u_time = get_the_time('U');
  7. $u_modified_time = get_the_modified_time('U');
  8. if ($u_modified_time >= $u_time + 86400) {
  9. $updated_date = get_the_modified_time('F jS, Y');
  10. $updated_time = get_the_modified_time('h:i a');
  11. $custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
  12. }
  13. $custom_content .= $content;
  14. return $custom_content;
  15. }
  16. add_filter( 'the_content', 'wpb_last_updated_date' );
  17.  
  18. tampilan dimodifikasi menggunakan style.css:
  19. .last-updated {
  20. font-size: small;
  21. text-transform: uppercase;
  22. background-color: #fffdd4;
  23. }
  24.  
  25. This code checks to see if a post’s published date and last modified dates are different. If they are, then it displays last modified date before the post content.
  26.  
  27. ========================================
  28.  
  29. CARA II
  30. =======
  31. This method requires you to edit specific WordPress theme files. Many WordPress themes now use their own template tags which define how these themes show post meta data like date and time.
  32.  
  33. Some themes also use content templates or template parts to display posts.
  34.  
  35. Few simpler themes will use single.php, archive.php, and other template files to show content and meta information.
  36.  
  37. You will be looking for the code responsible for displaying the date and time. You can then either replace that code with the following code, or add it right after your theme’s date and time code.
  38.  
  39.  
  40. $u_time = get_the_time('U');
  41. $u_modified_time = get_the_modified_time('U');
  42. if ($u_modified_time >= $u_time + 86400) {
  43. echo "<p>Last modified on ";
  44. the_modified_time('F jS, Y');
  45. echo " at ";
  46. the_modified_time();
  47. echo "</p> "; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement