🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

WordPress displays the last modified and updated posts

Yesterday, I sharedthe method to display the last modified time of articles on WordPress article pages. So, how do you let people know which articles have been modified? Of course, by displaying them on the frontend. Therefore, this article teaches you how to call and display a list of the most recently updated articles on WordPress.

Code Addition Method

Copy the code below and add it to your current theme's functions file. You can also use a plugin method:Safe method to add code to the functions.php file: Code Snippets
//显示最后更新的文章https://blog.naibabiji.com/skill/wordpress-xian-shi-zui-hou-geng-xin-shi-jian.html
function wpb_lastupdated_posts() { 
 
// 查询参数
$lastupdated_args = array(
'orderby' => 'modified',
'ignore_sticky_posts' => '1'
);
 
//显示最后更新的5篇文章
$lastupdated_loop = new WP_Query( $lastupdated_args );
$counter = 1;
$string .= '
'; $string .= ''; $string .= '
'; return $string; wp_reset_postdata(); } //添加一个短代码 add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');
The class 'widget-lastupdated' in the code above is added for you to customize the style. If you don't need it, you can delete that part of the code.
//不需要定制css样式就删除这两行
$string .= '
'; $string .= '
';
After adding the code, here is how to call it:

Frontend Calling Method

To call it within a template, use the following code:
Calling in Widgets or ArticlesUse the shortcode method:
[lastupdated-posts】
In the shortcode above, replace the 】 with ] when using.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step instead.

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan to Follow