Advertisement
eappereira

Category Show CHILDREN

Apr 16th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. $term = get_queried_object()->term_id;
  3. $termid = get_term($term, 'product_cat' );
  4. if($termid->parent > 0)
  5.     {
  6.         $args = array(
  7.             'orderby'       => 'name',
  8.             'order'         => 'ASC',
  9.             'hide_empty'    => false,
  10.             'child_of'      => $termid->parent,
  11.     );
  12.     $siblingproducts = get_terms( 'product_cat', $args);
  13.     foreach ($siblingproducts as $siblingproduct) {
  14.          if ($siblingproduct->term_id == $term ) {  ?>
  15.             <li>
  16.     <?php } else { ?>    
  17.             <li>
  18.     <?php } ?>    
  19.         <a href="<?php echo get_term_link( $siblingproduct ); ?>"><?php echo $siblingproduct->name; ?><?php echo "<span class='count'>" .  $siblingproduct->count . "</span>"; ?></a></li>
  20. <?php }
  21.     } else {
  22.         $args = array(
  23.             'orderby'       => 'name',
  24.             'order'         => 'ASC',
  25.             'hide_empty'    => false,
  26.             'child_of'      => $term
  27.         );
  28.     $subproducts = get_terms( 'product_cat', $args);
  29.     foreach ($subproducts as $subproduct) { ?>
  30.         <li> <a href="<?php echo get_term_link( $subproduct ); ?>"><?php echo $subproduct->name; ?><?php echo "<span class='count'>" . $subproduct->count . "</span>"; ?></a></li>
  31. <?php }
  32. }
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement