WordPress: Display recently updated posts & pages

Want to show a list of most recently updated posts and pages in WordPress? You can add a list of recently updated posts/pages by adding a code snippet to your WordPress theme in any template file where you want it to appear. Add this to one your templates to display a list of the posts and pages that were updated last.

<?php
     $today = current_time('mysql', 1);
     $howMany = 5; //Change to show desired number of entries
     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; ?>

Source: WP Snipp

Premium WordPress Themes

Reliable Web Hosting

Smart Web Worker strongly recommends HostGator for your website/blog hosting. Sign up for web hosting at just $3.96/month. Use the coupon code "SMARTBLOGGER25" to get 25% discount on any hosting packages. Get an account with HostGator now!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>