daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function li_build($li_fill_1, $li_fill_2,$li_choice){
  4.     if($li_choice == 1)
  5.     {
  6.         echo "<li class=" . "'sidebar-list-items'" . ">" .'<a href="'. get_term_link($li_fill_1, 'product_cat') .'">'. $li_fill_2 .'</a>'. "</li>";
  7.     }
  8.     elseif($li_choice == 2)
  9.     {
  10.         echo "<li class=" . "'sidebar-list-items'" . ">". '<a href="'. get_term_link($li_fill_1, 'product_cat') .'">'. $li_fill_2 .'</a>' . "</li>";
  11.     }
  12. };
  13.  
  14. function tag_sidebar(){
  15.  
  16. $category_profile = array(
  17.          'taxonomy'     => 'product_cat',
  18.          'orderby'      => 'name',
  19.          'show_count'   => 0,
  20.          'pad_counts'   => 0,
  21.          'hierarchical' => 1,
  22.          'title_li'     => '',
  23.          'hide_empty'   => 0
  24.   );; //get taxonomy in an array
  25.    
  26.  $all_categories = get_categories( $category_profile ); //get all the categories taxonomy
  27.  echo "<ul class=" . "'sidebar-parent-list'". ">";
  28.    
  29. //loop through each category that is a parent
  30. if(is_array($all_categories)){
  31.  foreach ($all_categories as $cat) {
  32.     if($cat->category_parent == 0) {
  33.     $tag = get_queried_object(); // get current page we're on
  34.         $category_id = $cat->term_id;      
  35.     $sub_category_profile = $category_profile;
  36.     $sub_category_profile['parent'] = $category_id;
  37.     $sub_category_profile['child_of'] = 0;
  38.         $sub_categories = get_categories( $sub_category_profile );
  39.        
  40.        
  41.     //loop through each subcategory
  42.         if(is_array($sub_categories)) {
  43.             foreach($sub_categories as $sub_category) {
  44.                
  45.                
  46.             //Display designer name with link to subcategory matching the current page we're on
  47.             $slugmatch = strpos($sub_category->slug, "-". $tag->slug);
  48.                
  49.             if($slugmatch)
  50.             {          
  51.                         li_build($sub_category->slug,$cat->name,1);
  52.             }
  53.             }  
  54.            
  55.         }
  56.     }      
  57. }
  58. }
  59.     else{
  60.         echo "Error Displaying Category List, Please Contact Webmaster";
  61.     }
  62.     echo "</ul>";
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top