Guest User

Untitled

a guest
Jan 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. <?php
  2. function tag_sidebar(){
  3. $taxonomy = 'product_cat';
  4. $orderby = 'name';
  5. $show_count = 0; // 1 for yes, 0 for no
  6. $pad_counts = 0; // 1 for yes, 0 for no
  7. $hierarchical = 1; // 1 for yes, 0 for no
  8. $title = '';
  9. $empty = 0;
  10.  
  11. $args = array(
  12. 'taxonomy' => $taxonomy,
  13. 'orderby' => $orderby,
  14. 'show_count' => $show_count,
  15. 'pad_counts' => $pad_counts,
  16. 'hierarchical' => $hierarchical,
  17. 'title_li' => $title,
  18. 'hide_empty' => $empty
  19. );
  20. $all_categories = get_categories( $args );
  21.  
  22. echo "<ul class=" . "'sidebar-parent-list'". ">";
  23.  
  24. foreach ($all_categories as $cat) {
  25. if($cat->category_parent == 0) {
  26. $tag = get_queried_object();
  27. $modname = str_replace(" ","-", strtolower($cat->name));
  28. $category_id = $cat->term_id;
  29.  
  30. $args2 = array(
  31. 'taxonomy' => $taxonomy,
  32. 'child_of' => 0,
  33. 'parent' => $category_id,
  34. 'orderby' => $orderby,
  35. 'show_count' => $show_count,
  36. 'pad_counts' => $pad_counts,
  37. 'hierarchical' => $hierarchical,
  38. 'title_li' => $title,
  39. 'hide_empty' => $empty
  40. );
  41. $sub_cats = get_categories( $args2 );
  42.  
  43. if($sub_cats)
  44. {
  45.  
  46. foreach($sub_cats as $sub_category) {
  47.  
  48. if($tag->slug == "earrings")
  49. {
  50. if(strpos($sub_category->slug, "earring") == true)
  51. {
  52. echo "<li class=" . "'sidebar-list-items'" . ">" .'<a href="'.
  53. get_term_link($sub_category->slug, 'product_cat') .'">'. $cat->name .'</a>'. "</li>";
  54. }
  55.  
  56. }
  57.  
  58. elseif($tag->slug == "ring" ||$tag->slug == "bracelet" || $tag->slug == "necklace" )
  59. {
  60. if(strpos($sub_category->slug, $tag->slug) !== false && strpos($sub_category->slug, "earring") != true)
  61. {
  62. echo "<li class=" . "'sidebar-list-items'" . ">". '<a href="'.
  63. get_term_link($sub_category->slug, 'product_cat') .'">'. $cat->name .'</a>' . "</li>";
  64. }
  65. }
  66. }
  67.  
  68. }
  69. }
  70. }
  71. echo "</ul>";
  72. }
  73.  
  74. add_shortcode('tagsidebar','tag_sidebar');
Add Comment
Please, Sign In to add comment