Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************************ BEGIN CAT FUNCTION
- function get_mymenu($curcat = 0, $depth = 1)
- {
- $current_cat ="";
- $breadcats = my_get_breadcats($curcat);
- $my_cats = my_get_all_categories();
- if($depth == 0){$listlevel = "parentlist";}
- else{$listlevel = "childlists";}
- $html = "$parentid<ul class=\"".$listlevel."\">";
- $categories = $my_cats[$breadcats[$depth]];
- if(isset($categories))
- {
- foreach ($categories as $cat)
- {
- $parent ="";
- $parentid = $cat->category_parent;
- $catid = $cat->cat_ID;
- if($depth == 1){$level = "levelone";}
- elseif($depth == 0){$level = "levelzero";}
- elseif($depth == 2){$level = "leveltwo";}
- elseif($depth == 3){$level = "levelthree";}
- else{$level = "";}
- if($curcat == $cat->cat_ID){$current_subcat = "current_subcat";}
- else{$current_subcat = "";}
- $anc = get_ancestors($curcat,'category');
- foreach($anc as $ancestor){
- if($ancestor == $catid) {
- $parent = "current-cat-parent";
- }
- }
- $html.= "<li class=\"cat-item ".$current_subcat." ".$level." ".$parent."\"><a href=\"". get_category_link( $cat->cat_ID ) ."\">". $cat->cat_name ."</a></li>";
- if ($cat->cat_ID == $breadcats[$depth+1] && $depth<count($breadcats))
- {
- $html.= get_mymenu($curcat, $depth+1);
- }
- $html.= "</li>\n";
- }
- }
- $html.= "</ul>\n";
- return $html;
- }
- function my_get_all_categories()
- {
- static $my_cats = array();
- if (count($my_cats)==0)
- {
- $categories = get_categories('child_of=0', 'orderby=name');
- foreach ($categories as $cat)
- {
- $my_cats[$cat->category_parent][$cat->cat_ID] = $cat;
- }
- }
- return $my_cats;
- }
- function my_get_breadcats($curcat = 0)
- {
- global $post;
- static $breadcats = array();
- if (count($breadcats)==0)
- {
- $curcat = intval($curcat);
- $breadcats[] = $curcat;
- while($curcat!=0)
- {
- $curcategory = get_category($curcat);
- $curcat = intval($curcategory->category_parent);
- $breadcats[] = $curcat;
- }
- $breadcats = array_reverse($breadcats);
- }
- return $breadcats;
- }
- //************************ END CAT FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement