[wp-hackers] exclude category from main loops via plugin

Paul paul at codehooligans.com
Mon Dec 13 13:13:22 UTC 2010

On Dec 13, 2010, at 8:03 AM, Alexander Höreth wrote:

> Hey there,
> I am working on a plugin which needs to exclude a post category from main loops. E.g. the loop processed on the index page but as well from archives etc.
> Normally I would use
> <?php query_posts($query_string . '&category_name=-mycategory'); ?>
> directly in the theme files.
> How do I add it using hooks?
> loop_start, parse_query or pre_get_posts?
> I already tried adding it, but it just killed the website..

I already have a plugin which does this exact thing. Check out Simply Exclude http://wordpress.org/extend/plugins/simply-exclude/

Works for post categories, tags and authors. You can exclude these items from 4 specific is_* functions : is_front, is_archive, is_search, is_feed.

The process for doing the actual exclude is somewhat trivial. Documented on both the WP Codex page http://codex.wordpress.org/Custom_Queries (scroll to the Category Exclusion section) and my own Simply Exclude page http://www.codehooligans.com/projects/wordpress/simply-exclude/


More information about the wp-hackers mailing list