Advertisement
pusatdata

Menampilkan List Update Terbaru di WP

Sep 30th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. Code in functions.php
  2. =====================
  3. function wpb_lastupdated_posts() {
  4.  
  5. // Query Arguments
  6. $lastupdated_args = array(
  7. 'orderby' => 'modified',
  8. 'ignore_sticky_posts' => '1'
  9. );
  10.  
  11. //Loop to display 5 recently updated posts
  12. $lastupdated_loop = new WP_Query( $lastupdated_args );
  13. $counter = 1;
  14. $string .= '<ul>';
  15. while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
  16. $string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
  17. $counter++;
  18. endwhile;
  19. $string .= '</ul>';
  20. return $string;
  21. wp_reset_postdata();
  22. }
  23.  
  24. //add a shortcode
  25. add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');
  26.  
  27.  
  28.  
  29. Theme:
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. https://www.wpbeginner.com/wp-tutorials/how-to-display-a-list-of-last-updated-posts-in-wordpress/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement