Created
June 5, 2010 22:36
-
-
Save matthewcrist/427063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function post_is_in_descendant_category($cats, $_post = null) { | |
foreach ( (array) $cats as $cat ) { | |
// get_term_children() accepts integer ID only | |
$descendants = get_term_children( (int) $cat, 'category'); | |
if ( $descendants && in_category( $descendants, $_post ) ) | |
return true; | |
} | |
return false; | |
} | |
function is_my_current_cat($id) { | |
if (is_category($id)) | |
return true; | |
if (is_category()) { | |
$descendants = get_term_children( (int) $id, 'category'); | |
if ( $descendants ) | |
foreach($descendants as $cate){ | |
if(is_category($cate )) | |
return true; | |
} | |
} | |
if (is_single()) { | |
if (in_category($id) || post_is_in_descendant_category($id)) { | |
return true; | |
} | |
} | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A couple helpers to help you figure out if you're within a category in Wordpress. A slight modification of code found here... | |
http://olykrap.com/post/how-to-check-for-category-descendants/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment