Guest User

Untitled

a guest
Mar 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. $category_id = get_query_var( 'cat' ); // Get current catgory ID
  2. $category = get_term( $category_id, 'category' ); // Fetch category term object
  3.  
  4. // Now, we check if the category has a parent
  5. // If it has, we use that ID
  6. // If it doesn't have a parent, it is a parent category itself and we use its own ID
  7. $parent = $category->parent ? $category->parent : $category_id;
  8.  
  9. $args = array(
  10. 'show_count' => false,
  11. 'hide_empty' => false,
  12. 'title_li' => '',
  13. 'show_option_none' => '',
  14. 'echo' => false
  15. );
  16.  
  17. // Show the children of parent category
  18. if ( $category->parent ) {
  19. $args['child_of'] = $category->parent;
  20. $args['exclude'] = $category_id; // Don't display the current category in this list
  21. }
  22. else {
  23. $args['child_of'] = $category_id;
  24. }
  25.  
  26. // Get the category list
  27. $categories_list = wp_list_categories( $args );
  28.  
  29. if ( $categories_list ) {
  30. ?>
  31. <div class="category-wrapper">
  32. <ul class="child-categories">
  33. <?php echo $categories_list; ?>
  34. </ul>
  35. </div>
  36. <?php
  37. }
Add Comment
Please, Sign In to add comment