Home / page / Display most recently updated posts and pages
  • How to Display most recently updated posts and pages

    display-most-recently-updated-posts-and-pages

    Adding this snippet to your wordpress theme will display a list of the most recently updated posts and pages.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    <?php
         $today = current_time('mysql', 1);
         $howMany = 5;
         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; ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_title, get_permalink, current_time, __, _e, wp,