wordpress hacks

Display Recently Updated Posts or Pages in Wordpress

by Franklin Bishop on June 9, 2009

This code will display recently updated posts or pages in Wordpress. This is actually one of my favorite things to do because it allows her readers and other visitors to know what you have recently updated. It will definitely raise your pageviews because people will likely want to know what you recently updated.

<?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; ?>

You can also change the code to your preferences. That way you can display recently updated posts or pages the way you would like. Wordpress makes this all possible.

Leave a Comment

Previous post: Display Recent Comments in Wordpress

Next post: Display Recent Posts in Wordpress