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