WordPress recently updated pages or posts

This WordPress plugin creates a list of links to the most recently updated pages and posts on any WP website. The following image is a screen shot of the widget output. I am running this widget on this website, so forget the screen shot. Look at the sidebar on this page and you will find the widget itself.

recently-updated-pages-and-posts

Install this plugin

  1. Download recently-updated-pages-and-posts.zip
  2. Decompress the file contents
  3. Upload the recently-updated-pages-and-posts folder to a WordPress plugins directory (/wp-content/plugins)
  4. Activate the plugin from the Administration Dashboard
  5. Open the Widgets page under the Appearance section
  6. Drag the Recently updated widget to the active sidebar
  7. Configure the widget options to suit your needs and click Save

Sample HTML output

View sample-html-output.txt

Styling the output with CSS

/* reference the list by id */
#recently-updated-widget-list{ list-style: disc; }

/* apply style to all of the list items */
.recently-updated-widget-item{ margin-left: 25px; }

/* make the first list item font size larger */
#ruwi-0{ font-size: 125%; }

WordPress.org plugin page

Visit this plugin’s page in the official WordPress Plugin Directory.

Here is some code I hacked together to display a list of recently updated pages and posts on a WordPress site:


<?php
$today = current_time('mysql', 1);
$howMany = 5;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<h2><?php _e("Recent Updates"); ?></h2>
<ul>
<?php
foreach ($recentposts as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
the_title();
echo '</a></li>';
}
?>
</ul>
<?php endif; ?>

The variable $howMany holds the number of items to display in the list. I used some code I found in a WordPress theme I am using on some website, and modified it to help someone in need of this specific solution.

Update 02/22/2010:

Including post excerpts

A commenter below asks, “Is it possible to combine the_excerpt(); with the code you provided?” The function you are naming is only useful inside “the loop,” but yes, including excerpts is easy. Try this:


<?php
$today = current_time('mysql', 1);
$howMany = 18;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title, post_excerpt FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<h2><?php _e("Recent Updates"); ?></h2>
<ul>
<?php
foreach ($recentposts as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
the_title();
echo '</a><p>' . $post->post_excerpt . '</p></li>';
}
?>
</ul>
<?php endif; ?>

46 comments

  1. Great tutorial :)

    One question; Is it possible to combine the_excerpt(); with the code you provided?

    What I mean is that I want to display a list of the recently updated post/pages with the excerpt.

    Hope you can help me :)

    Best Regards
    Knut

  2. Hi Corey,

    The new code that includes excerpts works perfectly. Thanks you so much!

    Now I have a new challenge for you; What would the code look like, if I want it to gather the 55 first words from a page / post?

    Hope you can solve this one ;)

    Best Regards
    Knut

  3. Fantastic plugin but could you tell me what file is it I use to style it or how do I style it.

    thanks in advance

  4. Thank you for the great widget. I would like to style the title ( I have called it Recent Updates). How do I reference it in order to do so?
    Thanks for the help.

  5. Hana:

    I need to publish an update so you can target the widget title with CSS. It’s not possible to single this element out by itself at this time.

  6. I love this plugin but have a glitch… it picks up Contact Form 7 forms as a recent posts/pages if they are edited but the links to the forms are invalid. It tries to link directly to the updated contact form.

    Is there a way to exclude the contact form elements so that it doesn’t think they are pages?

  7. fan:

    It sounds like you have some other plugin that creates pages or posts. Can you show me your site, I don’t understand why the links would be bad.

  8. hi
    is there anyway to make this a non widget plug in? I’m trying to make an updates page for my site but cant find any plug in that will do this, simple thing.

  9. Hi Corey,

    I’m struggling to get a “modified date” into the code you provided. The typical WP functions (the_modified_date and the_modified_time) don’t seem to work (not the right kind of loop?).

    Is there an easy way to display the date the post was modified?

  10. Phil:

    Your suspicion is correct. Widgets exist outside of the loop. You need to add post_modified to the SELECT database query. Then, use $post->post_modified to display it.

  11. James: I am not a BBPress user, but I suspect these items you are concerned about are stored in the posts table since my plugin is listing them. I’d have to learn about how those are stored in the database and then adjust the plugin for you. This doesn’t sound interesting to me, but if you are willing to pay me to make a custom version of the code just for you I will do it.

  12. Hi there,
    Hoping you’re still working on this plugin’s development, I have 2 questions:

    1) Is it possible to limit the Updated posts to the Custom posts only and not the default blog posts?

    2) Can we include thumbnails pulled from the custom posts?

  13. Fanatic, I could make that happen but no one is asking for . If you really want it you can pay me to make a custom version.

  14. Hello, its working very well, thank you, on the latest version of WP at the moment.

    I would like to however have it only show the posts and not the pages?

    How would one go about making this alteration.
    ThanxForThis

  15. I really like your plugin! Excellent work. I have been looking for this for a long time. I am wondering if there is a way to exclude certain types of posts. I have certain posts that are not actual posts but just “place holders” for images that are called by another plugin. But, those posts are being shown as “Recently update”. Regular post have ?=pxxx, but the posts that are place holders, have the following: ?post_type=pluginName&p=xxx. xxx is the id of the post. So when clicked on, a page not found appears. Thank you for a wonderful plugin!

  16. pico: If you would like to commission a custom version of the plugin, sure. That’s a feature I do not need, personally, so I have no reason to build it unless there’s something in it for me.

  17. Thanks for this – it’s exactly what I needed. However, I need to know how I can exclude post_type=feedback from being listed. I have Jetpack installed and anytime someone send us a message via a contact form, it lists their name º_º Thanks! »» Twitter @toasterdroid ««

  18. Jedediah: Line 56 contains the SQL query. You need to expand the WHERE clause to add AND post_type <> 'feedback'

  19. @Corey I added `AND post_type = ‘page’` and that seems to have worked. It weeded out blog posts and miscellaneous published content that isn’t otherwise accessible. Thanks!

  20. Sorry, one last thing. I don’t suppose you know how I can add the date each page was last updated after it’s closing tag? I’ve tried a few ways but they all return errors.

  21. It works beautifully but …. It includes pages & posts that have access limited. It shows everything regardless of their login status or access rights. If someone can’t access the page/post, it should not appear in the list.

    Any chance of a fix? Thanks.

  22. Hi Corey this is quite neat. I could try hacking about to edit it to suite my needs bumt wondering if you’re up for developing something slightly custom?

    I need a widget for a multi-site install which will display the most recently “updated” not created but modified custom post types from across the entire multisite network. There’s a few plugins which do this for recently created but nothing I can find for recently modified.

    Drop me a mail if you have time to create something like this relatively soon and an idea of cost

    thanks

  23. Hi Corey, yeah wpmudev have released a plugin called post indexer which fetches posts from across the network, that recent global posts widget places them based on some settings.

    It needs to be edited to include recently updated items.

    I just found this – http://en.8elite.com/network-latest-posts
    which seems to somehow do the job though it doesn’t include a date for the posts

  24. How can I get the same functionality for admin, NOT for front? The page search by date looks at creation date, not at last revision… :(

  25. Gave you a 5 star review of this on your plugin page on WordPress. Fully tested and working on WordPress 4.5.2 so I suggest you update it to say that.

    Works like a charm !!! Thank you so much, just what I needed and it WORKS !!!

Leave a comment

Your email address will not be published. Required fields are marked *