Skip to content

Instantly share code, notes, and snippets.

@JakeKalkman
Last active January 19, 2019 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JakeKalkman/db016d77e1df52a1a437155dc5f8d127 to your computer and use it in GitHub Desktop.
Save JakeKalkman/db016d77e1df52a1a437155dc5f8d127 to your computer and use it in GitHub Desktop.
<?php
function li_build($li_fill_1, $li_fill_2,$li_choice){
if($li_choice == 1)
{
echo "<li class=" . "'sidebar-list-items'" . ">" .'<a href="'. get_term_link($li_fill_1, 'product_cat') .'">'. $li_fill_2 .'</a>'. "</li>";
}
elseif($li_choice == 2)
{
echo "<li class=" . "'sidebar-list-items'" . ">". '<a href="'. get_term_link($li_fill_1, 'product_cat') .'">'. $li_fill_2 .'</a>' . "</li>";
}
};
function tag_sidebar(){
$category_profile = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'title_li' => '',
'hide_empty' => 0
);; //get taxonomy in an array
$all_categories = get_categories( $category_profile ); //get all the categories taxonomy
echo "<ul class=" . "'sidebar-parent-list'". ">";
//loop through each category that is a parent
if(is_array($all_categories)){
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$tag = get_queried_object(); // get current page we're on
$category_id = $cat->term_id;
$sub_category_profile = $category_profile;
$sub_category_profile['parent'] = $category_id;
$sub_category_profile['child_of'] = 0;
$sub_categories = get_categories( $sub_category_profile );
//loop through each subcategory
if(is_array($sub_categories)) {
foreach($sub_categories as $sub_category) {
//Display designer name with link to subcategory matching the current page we're on
$slugmatch = strpos($sub_category->slug, "-". $tag->slug);
if($slugmatch)
{
li_build($sub_category->slug,$cat->name,1);
}
}
}
}
}
}
else{
echo "Error Displaying Category List, Please Contact Webmaster";
}
echo "</ul>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment