Displaying recently updated pages/posts without widget

Sometimes we want to to show a list of pages on our site to let the visitors know which contents have been updated but we don’t want to use widgets for this. Now heee’s a way on how to display those recently updates pages without the use of widgets.

Copy the following codes into the section where you want to display the list. Normally this would be in the sidebar.php.

$today = current_time('mysql', 1);
$howMany = 3;
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("Recently updated pages"); ?></h2>
foreach ($recentposts as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
echo '</a></li>';
<?php endif; ?>

To change the number of items in the list to be displayed, change the number

$howMany = 3;

You can also style the list accordingly. For example, if you want every item in the list to have yellow background and black left border, we can set the CSS to like this:

#recentpage {
list-style: none;
background: yellow;
border-left: 4px solid black;

And edit the <ul> tag to

<ul id="recentpage">