Code for listing posts for a category

Anybody know how to lists, say the 5 most recent entries for a particular category ? I tried looknig through the codex but couldn’t find the code.

Keep it civil guys. Here’s an example of showing the 5 most recent posts for a category:

<?php
global $post;
$myposts = get_posts('category_name=Featured');
foreach($myposts as $post) :
    setup_postdata($post);
?>
<div class="post">
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <?php the_content(); ?>
</div>
<?php endforeach; ?>

If this is your front page, then you can set that in the settings without having to deal with the code - sets how many posts show up on the first page.

If you are setting it for something else, let us know :slight_smile:

what’s your problem? yes, you don’t need php for Wordpress - unless you start customising it. and seriously, learning the php basics isn’t all that difficult.

am i doing something wrong here. I have this code but it doesn’t work. i’m trying to show the lasts 5 posts from the category id of 3


 <?php get_posts('category=3&numberposts=5'); ?> 

gosh thanks. i’ll have to remember that one before i waste your precious time again. geez…

everything i was told about wordpress was that it was easy to learn and didn’t have to know php.

should’ve said that you don’t know much about php - in which case it’d be a good idea to learn some of the php basics first - variables, arrays, functions - otherwise it’d be like you’d go to China tomorrow without knowing one word and nothing about its culture.

or maybe i did but just am a complete php newb that some of this is over my head.

i will look again and try to decipher.

http://codex.wordpress.org/Function_Reference/get_posts
use the arguments to get posts from a specific category.

doesn’t look like you checked out the example on that page, otherwise you’d see your error immediately. get_post builds an array of those posts, so you need to populate an array variable, and then use foreach to loop through - but that’s all explained on the page I linked to.