Ok, I just spent the better part of ALL DAY trying to figure this out.
I want my wordpress category.php template to be able to detect whether the category it is serving is a parent category or subcategory. THATS IT. And without having to hard code any category ID’s. After perusing the forums and codex for a couple of hours, the marriage of these two functions seemed to get the job done.
get_query_var is the variable stored in the query that tells category.php what category to serve.
get_category retrieves category data given a category ID or category object.
Here’s the function that goes in your functions.php file:
function is_subcategory (){
$cat = get_query_var('cat');
$category = get_category($cat);
return ( $category->parent == '0' ) ? true : false;
}
Then you can use this in your category.php file to determine if the category you are serving is a parent category or subcategory:
if ( is_subcategory() ):
//displaying subcategory
else:
//displaying parent category
endif;
Hope this helps some people out there.
*note: both code snippets should be wrapped inside php brackets. <?php ?>


Moving out is awesome!
So recently my girlfriend and I moved in to a duplex in Bushwick, Brooklyn. This is our first foray into living on our own, and so far it has been awesome.
2 awesome roommates. Lots of friends nearby.
I have been very busy as of recently. Working on a lot of projects.
2010 off to a great start.
Cheers!
Tags: brooklyn, Bushwick, roommates