From a quick look at the documentation for get_posts(), it doesn't look like you can exclude a post based on its category.
EDIT: Actually, thanks to AntonChanning, turns out you can - just add
&cat=-1 to your argument string, where 1 is the ID of the category you wish to exclude:
$postslist = get_posts('numberposts=1&order=DESC&orderby=date&cat=-1');
You can also add multiple categories to this if you need to, eg.
The preferred 'Wordpress way' to do this is using WP_Query.
If you want to do it this way, instead of your call to
get_posts(), you'll need to create a new instance of WP_Query and pass your arguments through in an array. From the above link under the Category Parameters heading:
category__not_in (array) – use category id
That's the argument you'll want to use to exclude a category:
$postslist = new WP_Query(array(
"post_type" => "post",
"posts_per_page" => 1,
"order" => "DESC"
"orderby" => "date",
"category__not_in" => 1,
You'll notice I also added the 'post' post type to mimic the behaviour you would have had with
get_posts(), and the
posts_per_page parameter is the way to specify the number of posts returned with WP_Query.
One other change you'll need to make if you do go down this WP_Query route is to use a
while loop instead of the
foreach you currently have. There's clear usage examples under the Usage heading in the docs so I'll avoid copying and pasting them out.