Tuesday, December 1, 2020
Home Blogging How to Display a List of Last Updated Posts in WordPress

How to Display a List of Last Updated Posts in WordPress

At GyanHiGyann, we present final modified date as an alternative of unique revealed date for all of our articles. We expect it’s dangerous thought to take away dates out of your WordPress weblog posts. In case you are utilizing final modified date, then you definitely would possibly wish to present a listing of your just lately up to date posts in your web site. On this article, we’ll present you show a listing of last updated posts in WordPress.

Every time you replace a publish, WordPress shops the date and time of that replace within the posts desk as final up to date date. We are going to present you create a customized WordPress question to record your most just lately up to date articles.

Copy and paste this code in a site-specific plugin or your theme’s capabilities.php file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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');

That’s all. Now if you wish to show last updated posts in your theme’s template recordsdata, then you should use it like this:

1
2
3
4
5
<?php
if (function_exists(wpb_lastupdated_posts)) :
wpb_lastupdated_posts();
endif;
?>

To show last updated posts in WordPress posts, pages, and widgets, then you should use the shortcode [lastupdated-posts].

There are various alternative ways to type your articles in WordPress. Other than the ascending, descending, and random order, you can even show posts by expiration date. With this text, now you can present posts by the final modified time.

You May Also Like : How to Add Google Maps in WordPress

How would you employ this in your web site? Are you displaying unique revealed date or final modified date? Tell us by leaving a remark beneath.

If you happen to preferred this text, ensure to hit the bell for getting our newest updates and share this text with your pals in each social media platforms.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

How to make money with Toluna surveys

Toluna is most well-known for its surveys, however there are an entire host of different methods to earn rewards on the location. Our assessment...

6 Best Free Alternatives To Camtasia 2020 For Mac And Windows

I really like Camtasia and have been an avid person of Camtasia ever since 2012. Recently, the Camtasia workforce launched the 2019 model of Camtasia which...

List of Travel Affiliate Programs For Travel Bloggers

For me, touring is freedom. If you're a journey blogger, I offer you a standing ovation. Being a digital nomad, I perceive how powerful it's to weblog whereas touring. I additionally...

Social Warfare Review: Explode your Social Shares

Everybody is aware of that having social media sharing buttons is important for each weblog within the Blogosphere. Why? Well, social media sharing buttons assist us...

Recent Comments