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.

Recent updates

Install this plugin

  1. Download recently-updated-pages-and-posts.zip (mirror)
  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; ?>

18 Comments so far

  1. [...] goes to Corey for this awesome [...]

  2. Philip on September 4th, 2009

    Oh sweet … Ive been trying to do this for a while … Thanks for posting it have used it on my website.

  3. COMPUTELOGY on November 15th, 2009

    Hi,
    Is there any way to have such code for blogspot?
    Regards,

  4. [...] Source: Corey [...]

  5. [...] Source: Corey [...]

  6. Knut on February 22nd, 2010

    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

  7. Corey on February 22nd, 2010

    I have added some code above to include post excerpts. Let me know how it works out for you.

  8. Knut on February 23rd, 2010

    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

  9. [...] Source: Corey [...]

  10. [...] Source: Corey [...]

  11. ails on December 19th, 2010

    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

  12. Corey on December 19th, 2010

    ails:

    I have actually launched a plugin based on this code:

    http://wordpress.org/extend/plugins/recently-updated-pages-and-posts/

    I see there is an opportunity to add some element IDs and classes for CSS, and I will release an update to include these items.

  13. ails on December 20th, 2010

    @ Corey … thank you very much ..I’ll look forward to that.

  14. Fask on April 2nd, 2011

    Hi,

    is possible hide newly published, but yet unmodified posts ? would be really great…

  15. Hana on October 23rd, 2011

    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.

  16. Corey on October 24th, 2011

    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.

  17. fan on November 30th, 2011

    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?

  18. Corey on November 30th, 2011

    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.

Leave a reply

 

Thanks for reading!

Sign up for email updates: