How To Exclude Posts Of A Certain Category In Thesis

by Matt on August 18, 2009

Categorical Exclusion

Sometimes, there is a benefit to excluding posts of a certain category from the main blog page. For instance, you may want a page that updates frequently. Rather than go in and edit the page each time you want new content, you could simply write a post, mark it in a special category, exclude that category from the main blog [this tutorial], and have posts within the special category appear on the page [another post]. Shoo! That sounds like a lot, but it is actually very simple.

Consider this post part of a series in which I will explain the process of excluding a post from the main blog, then having it appear on another page [instead of page content, that is].

The Code

Alright guys and gals, this is super easy to pull off. Simply copy and paste the code in the box below and change the number to the Category ID for your site. That’s it!

function exclude_cat($query) {
if ( $query->is_home) {
	$query-> set('cat','-13');
	}
return $query;
}
add_filter('pre_get_posts','exclude_cat');

Don’t forget to get your copy of Thesis!

{ 1 trackback }

Filtering post on homepage give unexpected result - DIYthemes Forums
September 9, 2009 at 9:28 pm

{ 11 comments… read them below or add one }

Kat August 28, 2009 at 11:55 am

THANK YOU!

Conrad September 12, 2009 at 9:20 pm

Great tip, thanks!

marc mcdermott December 13, 2009 at 9:07 pm

Why does thesis have to be so limiting!? Very frustrating as a traditional coder. Thanks for the simple tutorial, saved me a lot of time! Cheers.

Matt December 13, 2009 at 9:22 pm

@Marc
In what way do you think Thesis is limiting? This particular tutorial doesn’t even call a single Thesis function. I guess I’m confused by how you arrived at your conclusion.

Gen3Chip December 17, 2009 at 10:05 pm

Thanks a ton for this Matt!!! I must of spent a couple hours digging around on the thesis forums looking for this. Pretty frustrating. That will teach me to not check here first. All the Best.

Matt December 18, 2009 at 11:48 am

@Gen3Chip
Feel free to ask me any question at any time.

Pete December 30, 2009 at 4:17 pm

Thanks Matt! I think this is exactly what I need. Question… By posting the code in custom functions.php, does that exclude the post w/that excluded category from appearing everywhere? Or only on the main page? I’m assuming I can place a category link in the nav bar, and by clicking on it, you’d see the post. I’d originally wanted to have the front page as a blog page, as well as the developer’s blog pg, and a deals pg…all pages that would be dynamic, til I found out it’s not feasible. I guess this solves it though, instead of having an actual blog page for my blog, I’d just make all posts, then determine where they’ll go with the categories tag. If this solves that, perfect, gets rid of a huge organization issue, and actually makes it easy, as I’ll be able to post from one place, and funnel it wherever I wanted. I did want to make sure that not every single category I posted to ended up on the main page, so if I’m understanding right, you solved it for me. Thanks!

Pete December 30, 2009 at 4:23 pm

Sorry, one more question. If there are 2-3 categories I want excluded, would I duplicate the entire code, or only line 3, specifying the category, or would I just add a , and the additional category(s)? Thanks again!

Lewis Dexter Litanzios January 19, 2010 at 9:32 pm

Cheers mate. Clear, concise post. Great video. Just what I needed. Just been given Thesis to use in my new job; coming from working directly with the traditional Wordpress codex.

I must say, working out how to exclude a category from the loop all over again made me feel a bit stupid. Pro’s and con’s to Thesis overall. It definitely saves time in getting a basic blog online, but forget about anything custom – I think it would be easier to achieve with codex.

Thanks again,

Calin February 27, 2010 at 5:43 am

Hi,

Very nice customization. Congratulations. My question is: how can I add a category in Menu? I means, how can I show the post from category like in your site, not a simple list? Because simple change in Thesis Options, display only the list, not teasers

Thank you

Matt February 28, 2010 at 11:04 pm

@Calin
You have to set up your entire site to show teasers.

Leave a Comment

Previous post:

Next post: