Check out this plugin: http://ryowebsite.com/?p=46
It lets you exclude categories from the front page, archives, rss, etc.. It also satisfies your requirement of not limiting the number of posts when it excludes them.
Thanks Otto42. That plugin did some stuff I didn’t want, but it helped by pointing me in the right direction.
Actually, I discovered that there’s a pretty simple plugin fix to do what I want, as long as you’re using MySQL 4.1 or newer (older versions don’t work because they don’t support subqueries):
function modify_where_clause($where) {
global $wp_query, $wpdb;
if ($wp_query->is_home && !strstr($where,'category_id'))
$where .= " AND ID NOT IN (SELECT post_id FROM $wpdb->post2cat WHERE category_id=2)";
return $where;
}
add_filter('posts_where','modify_where_clause');
This removes all posts of category id 2 from the loop and doesn’t interfere with specific requests you might have for category 2 (in my case, a sidebar blog of only category 2 entries).
can’t you use query_posts to handle this as well?
http://codex.wordpress.org/Template_Tags/query_posts
I don’t know if that info is outdated but it has worked for me.
Okay, I see what you’re saying. The problem is that something like query_posts("cat=-3"); excludes a post of category 3 only if that post is under just category 3. If you’ve assigned it other categories, then it’s not excluded.
@filosofo: where would I put that code? I’m having problems with that as well…
mae, you could put it in your theme’s functions.php file.
yes! it worked! thanks a lot filosofo!
How would you modify the where clause for the RSS feeds?
i have the same question as highwind.
ALSO.. i’ve managed to use a few ifelse statements to exclude the categories i want from the loop, but i have the same problem as the original poster in this thread.
how can i exclude the categories but still preserve the recent post count ??
i’m assuming i could use this code… but how would i modify it to exclude multiple categories ?
function modify_where_clause($where) {
global $wp_query, $wpdb;
if ($wp_query->is_home && !strstr($where,’category_id’))
$where .= ” AND ID NOT IN (SELECT post_id FROM $wpdb->post2cat WHERE category_id=2)”;
return $where;
}
add_filter(‘posts_where’,’modify_where_clause’);
also, i’m not sure exactly where to put that little bit of code, or how to call it. can anyone help ?
I’m sort of wondering about the same thing. I want to INCLUDE multiple categories, or more correctly, I want to do this more than one time on the same page (as outlined here).
Possible?