Display Recently Updated Posts/Pages


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $today = current_time('mysql', 1);
  3. $howMany = 5; //Number of posts you want to display
  4. 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")):
  5. ?>
  6. <h2><?php _e("Recent Updates"); ?></h2>
  7. <ul>
  8. <?php
  9. foreach ($recentposts as $post) {
  10. if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
  11. echo "<li><a href='".get_permalink($post->ID)."'>";
  12. the_title();
  13. echo '</a></li>';
  14. }
  15. ?>
  16. </ul>
  17. <?php endif; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.