Exclude certain categories from home page

by michael

Here is the code that you need to insert into thesis custom_functions.php to exclude certain categories from the home page

function exclude_cat_from_home() {
global $query_string;
if (is_home()) {
query_posts($query_string . ‘cat=-5′);
}
}
add_action(‘thesis_hook_before_content’, ‘exclude_cat_from_home’);

Find you categories ID from the Categories section in wordpress, then place your mouse over the category and you will see in the status bar on your browser cat_ID=x at the end or you can just press edit on the category and you will see it stated in the address bar and grab the cat_ID=x at the end as well.You can add more than one category to be filtered by adding more to it.

query_posts($query_string . ‘cat=-5,-7,-8′);

If you want to do it the other way around, say too many categories to exclude from, you can just write the code the other way (just without the ‘-’ sign) and it will only show that particular categories in the list.

query_posts($query_string . ‘cat=2,3′);

If you filter out a parent category, it will also filter out all posts under its child categories, so you have to target the specific child category if you still want to show the posts in the parent category.

Share this

No related posts.

{ 1 trackback }

Tweets that mention Thesis: Exclude certain categories from home page -- Topsy.com
February 6, 2010 at 3:07 pm

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: