Display recently updated wordpress posts and pages

November 11, 2008 · Print This Article

Ever wanted to be able to display posts and page that have been updated recently?

 

Paste this code anywhere you’d like to display a list of recently updated posts and pages.

 

You can specify how much item to show by editing the value of the $howMany variable.

 

<?php
$today = current_time('mysql', 1);
$howMany = 5; //Number of posts you want to display
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; ?>


Your choice for site templates and wordpress themes

Comments

One Response to “Display recently updated wordpress posts and pages”

  1. rablegen on November 13th, 2008 11:44 pm

    I like this script!

    Does it work for pages as well? Or do I need to revise it and swap out every instance of ‘post’ with ‘page’ ?

    Rich

Got something to say?

You must be logged in to post a comment.