Showing the latest posts from a specific category

I wanted to show a post only from a recent post from certain categories

so far this is what I have:

<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 to turn it into this but doesn't work

<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 I am doing wrong ....

+2


a source to share


2 answers


why don't you give it a try (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; ?>

      

0


a source


According to the Codex, you cannot use the wp_get_recent_posts()

way you do:

Parameters

$ Num (integer) (optional) The number of messages to receive.

Default: 10



Maybe the codedude example helps.

+1


a source







All Articles