This is a useful function I use for building conditional statements to check whether a category is a subcategory (.e. has a parent).
In your functions.php file insert the following:
[php]
function is_subcategory (){
$cat = get_query_var(‘cat’);
$category = get_category($cat);
$category->parent;
return ( $category->parent == ‘0’ ) ? false : true;
}
[/php]
Then in your theme you can use the conditional as follows:
[php]
if ( is_subcategory() ) {
// do required actions
}
[/php]
If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.