Posted By

Ashung on 12/04/08


Tagged

wordpress category


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

lilumi
tmbrenneke
maxvee8
cyberhobo


wordpress in subcategory


 / Published in: PHP
 

wordpress in subcategory

  1. <?php
  2. function is_subcategory ($id) {
  3. $in_subcategory = false;
  4. foreach( explode( "/", get_category_children($id) ) as $child_category ) {
  5. if( in_category($child_category) ) {
  6. $in_subcategory = true;
  7. }
  8. }
  9. return $in_subcategory;
  10. }
  11. ?>
  12. <?php if ( is_category(1) || is_subcategory(1) ) { ?>
  13. ....LOOP....
  14. <?php } ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: cyberhobo on August 26, 2009

I wasn't finding getcategorychildren() in WP 2.8.4, so I did:

function insubcategory( $catid ) { $subcats = gettermchildren( $catid, 'category' ); if ( $subcats && !iswperror( $subcats ) ) { foreach( $subcats as $childcategory ) { if( incategory($childcategory) ) { return true; } } } return false; }

You need to login to post a comment.