How to add classes in the wp_list_category parent link

How do I add classes in the wp_list_category , I know the wp_list_categories(‘title_li=’);
generates classes , but I want to add a class in the parent category link

<ul>
  <li><a href="#"> link1</a> </li>
  <li><a href="#">link2 </a> </li>
  <li><a href="#">link3 </a>    <---how do I add a special class here
      <ul class="children">  
        <li><a href="#">link3 children </a> </li>
        <li><a href="#"> link3 children</a> </li>
      </li>
 </li>
 </ul> 

Im planning to use a jquery UI accordion in here,
please help. thank you

Read More

-edit–
problem solved by Paul , thanks man

Related posts

Leave a Reply

3 comments

  1. jquery accordion accepts an option called header that allows you to provide a selector to designate the items you want to act as the accordion headers.

    $('li.categories > ul').accordion({ header: 'li.categories > ul > li' });
    

  2. I have gotten this to work mainly by reverse-engineering the access-keys plugin. The code is pasted below but feel free to checkout the code for that plugin. It may help you decipher whats going on a little better.

    add_filter('wp_list_categories', 'my_class_name_cats');
    function my_class_name_cats($cats) {
            return preg_replace_callback('!(<li class="cat-item (cat)-item-([0-9]*)">[sS]*?<a([^>]*)>)!ims', 'my_class_name_finish', $cats);
    }
    
    add_filter('wp_list_pages', 'my_class_name_pages');
    function my_class_name_pages($pages) {
        return preg_replace_callback('!(<li class="page_item (page)-item-([0-9]*)"><a([^>]*)>)!ims', 'my_class_name_finish', $pages);
    }
    
    function my_class_name_finish($matches){
        $id = $matches[3];
        $link = $matches[0];
        $class = $matches[4]. ' class="page-'.$id.'" ';
        $link = str_replace($matches[4], $class, $link);
        return $link;
    }
    

    You can change class=”page-‘.$id.'” to whatever you would like. Currently it sets the class to page-[id of page or category]

    Add the code to your themes functions.php. If you only want it for categories you can ignore the wp_list_pages filter.

    Hope this helps.