Display WordPress posts of only one category

I am trying to display WordPress posts of only one category called news on my page… However I can’t seem to make it work, it still displays all posts. Any idea what I am doing wrong? The code is

<?php
 $postslist = get_posts('category=news&numberposts=10000&order=DESC&orderby=date');
 foreach ($postslist as $post) :
    setup_postdata($post);
 ?>
 <li>
 <?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
 <br><span class="caption"><?php the_time(get_option('date_format')) ?></span>
 </li>
 <?php endforeach; ?>

Thanks

Related posts

1 comment

  1. You try to get the category by name.

    But your code is not correct for this method.

    Try this:

    $postslist = get_posts('category_name=news&numberposts=10000&order=DESC&orderby=date');
    

    Or use the category ID to get your results:

    $postslist = get_posts('category=1&numberposts=10000&order=DESC&orderby=date');
    

    You can read more about get_posts here:

    http://codex.wordpress.org/Template_Tags/get_posts

Comments are closed.