Support » Fixing WordPress » wp_list_categories does not generate current-cat-parent for custom taxonomies

  • Hey,

    I’m using this to output a list of my custom taxonomies:
    <?php wp_list_categories('taxonomy=test'); ?>

    This works as it should, it assigns the current-cat class but it doesn’t assign the current-cat-parent as it normally does when I use wp_list_categories to list the categories for my normal posts.

    Anyone any idea?

Viewing 1 replies (of 1 total)
  • I’ve made a script to assing the parent class manually, but it does not quit work yet. It looks for the active child and then replaces the class of the ul that it’s in.

    <ul>
    <?php
    $categories = wp_list_categories($args);
    $category_array = preg_split('/\n/', $categories);
    $count = count($category_array);
    $i = 0;
    while ( $i < $count ) {
    	if ( preg_match('/current-cat/i', $category_array[$i+1]) ) {
    		echo preg_replace('/<ul class=(\'|")children(\'|")>/i', '<ul class="children current-cat-children">', $category_array[$i]) . "\n";
    	} else {
    		echo $category_array[$i] . "\n";
    	}
    	$i++;
    }
    ?>
    </ul>

    It only works and adds the parent class when the first child is active and thus has the current-cat class assigned, not when any other child is selected.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_list_categories does not generate current-cat-parent for custom taxonomies’ is closed to new replies.