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
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.