Short answer: You can’t.
Longer answer: You’d need to build your own category listing function – perhaps using get_categories().
Hmm… I’m listing the taxonomies of a custom post type. So not sure it would work. Could you use preg_replace just to tack it onto the end?
Found this which adds an ‘id=xx’ to the ‘li’ but doesn’t alter the url.
function add_id_from_slug($wp_list_categories) {
$pattern = '/class=/';
$replacement = 'id="xx" class=';
return preg_replace($pattern, $replacement, $wp_list_categories);
}
add_filter('wp_list_categories','add_id_from_slug');
Do you know if it could be altered to add to the the url? Otherwise it’s the dreaded walker class for me.
Thanks.
Aha! so got it working using a filter.
function filter_categories($output, $args=array()){
return preg_replace('/(\<a\shref=\"?[^\>]+?)\"/', '$1?area=map"', $output);
}
add_filter('wp_list_categories', 'filter_categories', 10, 2);
outputs: http://www.mysite.com/area/central/?id=map
Last hurdle. How do I get it to add that filter only from a certain page.
I need to get if is_page in there but it won’t work, probably due to my bad php.
Any pointers appreciated.
Thanks
No worries got it working using ‘$id = get_the_title();’ then on the next page I’ll use a simple get_id and if, else to display different content. Quite static really, but works for what i need. final code:
function filter_categories($output, $args=array()) {
$id = get_the_title();
return preg_replace('/(\<a\shref=\"?[^\>]+?)\"/', '$1?id='. $id .'"', $output);
}
add_filter('wp_list_categories', 'filter_categories', 10, 2);