Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code in functions.php
- =====================
- function wpb_lastupdated_posts() {
- // Query Arguments
- $lastupdated_args = array(
- 'orderby' => 'modified',
- 'ignore_sticky_posts' => '1'
- );
- //Loop to display 5 recently updated posts
- $lastupdated_loop = new WP_Query( $lastupdated_args );
- $counter = 1;
- $string .= '<ul>';
- while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
- $string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
- $counter++;
- endwhile;
- $string .= '</ul>';
- return $string;
- wp_reset_postdata();
- }
- //add a shortcode
- add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');
- Theme:
- 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