Thesis: how to remove multiple categories from your homepage

published on May 27, 2010 in Blogging

Here is a quick tutorial on how to modify your Thesis theme (WordPress framework) in order to remove one or more categories from appearing on your blog homepage.

For those who don’t know much about the Thesis custom_functions.php file, WordPress hooks, and how to retrieve category ids from the database, here is a quick summary.


PHP file located in the wp-content > themes > thesis > custom folder, custom_functions.php is where you should add PHP functions to modify the way the Thesis framework behaves. This is the file where you need to add to copy/paste the function below.

WordPress and Thesis Hooks

Hooks help insert functions the “normal” flow of the page. In terms of removing categories from the Loop, this needs to happen fairly early in the process of the page being created.

Retrieving category ids

In your WordPress admin section simply put your mouse cursor over the link to edit a category. You’ll notice at the bottom or your browser bar the full address of where the link points to. The number that interests you is the cat_ID=xx.

How to find WordPress Category ID

The function

function my_custom_loop(){
	global $wp_query; 
	$toExclude = '-3,-9';
	if(is_home()) {	query_posts(array_merge(array('cat' => $toExclude),$wp_query->query)); }
} add_action( 'thesis_hook_before_content', 'my_custom_loop' ); 

The function explained

  1. Line 1 creates and names the PHP function;
  2. Line 2 calls the global variable $wp_query allowing us to modify it later;
  3. Line 3 puts the cat_ID you want to hide into a new PHP variable called $toExclude. To remove categories use the minus (-) sign separated by comas. This line remove the categories 3 and 9 from the loop
  4. Line 4 is where the fun part happens. It first checks that we are on the homepage: we use the homepage as blog main page and can therefore use is_home(). If you use a static homepage and want to remove categories from that loop, use is_front_page() instead. It then modifies the loop query by merging /removing the categories from the global WordPress query.
  5. The last line
  6. tells Worpdress to run that function on the thesis_hook_before_content.

If you have any questions or comments, please share them in the comments below.


Leave a Comment. This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.

CommentLuv badge

Previous post:

Next post:

©2017 - All rights reserved
Site Map | Legal Stuff