Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'digimag_top_categories' ) ) :
- function digimag_top_categories() {
- $list_args = 'sort_column=name&sort_order=asc&style=list&depth=0&hierarchical=true&title_li=0&hide_empty=1&echo=0';
- $catlist = wp_list_categories($list_args);
- if ( is_category() ) {
- //Get the active category id
- global $cat;
- $curr_cat = get_category($cat);
- $catid = $curr_cat->cat_ID;
- //Find the top level id and number of levels
- while ($catid){
- $curr_cat = get_category($catid);
- $catid = $curr_cat->category_parent;
- $id[] = $curr_cat->cat_ID;
- }
- //How many levels more than two set hierarchical ancestor?
- //Count from 1 array from 0 : 1:0=Current 2:1=Parent >2:1 all Ancestors
- if( count($id) > 2){
- $max=count($id)-1; //Array elements zero based = count - 1
- $extra_class='current-cat-ancestor';
- for ( $counter = 1; $counter <= $max; $counter ++) {
- $cat_ancestor_class = 'cat-item cat-item-'. $id[$counter];
- $amended_class = $cat_ancestor_class . ' ' . $extra_class;
- $catlist = str_replace($cat_ancestor_class, $amended_class, $catlist );
- }
- }
- }
- $menu = str_replace( array( "\r", "\n", "\t" ), '', $catlist );
- echo $menu;
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement