Display last modified date on a Wordpress site

爱⌒轻易说出口 提交于 2019-12-11 16:12:12

问题


I was wondering if anyone knows an effective way of displaying the last modified date on a Wordpress site.

I'm not interested in the last modified date of a single post or page, but in a date (and maybe time) that shows the last time ANY modification was made on a site.

For example:

  • I modify the "Hello World" post on 15/09/18
  • I modify the "Sample page" page on 16/09/18
  • The "My last modified" displays "16/09/18" on the "Hello World" post and also on the "Sample page" page.

I'm aware of the the_modified_date() and the get_the_modified_date() functions, but I'd like to effectively show the latest from all of the modified content (pages, posts, custom post types, etc.)

Thank you for your suggestions in advance!


回答1:


You could query the most recently updated posts and pages, then pull out the updated date from there. Try something like this.

$recently_updated_posts = new WP_Query(array(
    'post_type'      => array('any'),
    'posts_per_page' => 1
    'orderby'        => 'modified',
    'no_found_rows'  => true, // speed up query when we don't need pagination
));

Then, you can use the $recently_updated_posts in the standard WordPress loop and have access to the_modified_date() and the get_the_modified_date() functions.



来源:https://stackoverflow.com/questions/52384099/display-last-modified-date-on-a-wordpress-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!