Wordpress

aaronchem

New Member
I currently have a site with a hard-coded list of categories & subcategories, where each item is formatted as follows:\[code\]<li class="cat-item open-access"><a href="http://stackoverflow.com/categories/open-access/">Open Access</a></li>\[/code\]Importantly, each \[code\]<li>\[/code\] item is assigned a class which matches the slug of the category linked to within.I would obviously like to use Wordpress' \[code\]wp_list_categories()\[/code\] to output the list instead of hard-coding it, but need to keep the custom class for each \[code\]<li>\[/code\] item.I have been looking into filters and actions and thought I might have come up with a fix by adding this to my theme's \[code\]functions.php\[/code\] file:\[code\]function add_class_from_slug($wp_list_categories) { $pattern = '/class=\"/'; $replacement = 'class="'.$category->slug.' '; $newclass = preg_replace($pattern, $replacement, $wp_list_categories); return $newclass;}add_filter('wp_list_categories','add_class_from_slug');\[/code\]But this doesn't work
 
Back
Top