WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_categories does not generate current-cat-parent for custom taxonomies (2 posts)

  1. DennisvanHouts
    Member
    Posted 4 years ago #

    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?

  2. DennisvanHouts
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.