Showing recent post from a specific category

I wanted to show post from just recent post from a specific categories

so far this is what I have but:

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

I tried turning it into this but not working

<ul>
    <?php
    $number_recents_post = 5;
      $recent_posts = wp_get_recent_posts($number_recents_post . 'cat=3,4,5');
      foreach($recent_posts as $post){
        echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a> </li> ';
      } ?>
    </ul>

Please let me know what am I doing wrong….

Related posts

Leave a Reply

2 comments

  1. According to the Codex, you can’t use wp_get_recent_posts() the way you do:

    Parameters

    $num
    (integer) (optional) Number of posts to get.

    Default: 10

    Maybe codedude’s example helps.

  2. why don’t you try this (assuming you are using WordPress)

    <?php query_posts('post_per_page=5&category_name=yourcategoryname'); ?>
    <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
    
    <?php endwhile; else: ?>
    
    <p>An error Message</p>
    
    <?php endif; ?>