Posted By

cyberhobo on 08/26/09


Tagged

wordpress category children wordpress-template in-subcategory


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

rickfu
umang_nine


WordPress: in subcatory?


 / Published in: PHP
 

URL: http://codex.wordpress.org/Function_Reference/get_term_children

Usually use in a template with in_category(), like if ( in_category( 3 ) || in_subcategory( 3 ) ) { .... Tested in WP 2.8.4.

  1. function in_subcategory( $cat_id ) {
  2. $subcats = get_term_children( $cat_id, 'category' );
  3. if ( $subcats && !is_wp_error( $subcats ) ) {
  4. foreach( $subcats as $child_category ) {
  5. if( in_category($child_category) ) {
  6. return true;
  7. }
  8. }
  9. }
  10. return false;
  11. }

Report this snippet  

You need to login to post a comment.