WordPress Recent posts without plugin

Following code is used to display most recent posts. We can limit number of posts displayed by specifying number of posts we want to display.

    <h2>Recent Posts</h2>
      $number_recents_posts = 5;//Enter number of recent of posts you want to display
     $args=array('numberposts' => $number_recents_posts,'post_status'=>'publish');

      $recent_posts = wp_get_recent_posts( $args );
      foreach($recent_posts as $post){
        echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a> </li> ';
      } ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

One Comment

  1. Thanks Neel. Works great. Just what I was looking for.