Off the top of my head, you can achieve the desired effect in two different ways.
Extend the Category Walker
Extend the Walker_Category()
class and overwrite the start_el()
method with similar code that retrieves a list of posts in the category being processed and displays them in an unordered list within the category’s <li>
element. To use your new walker class, pass it’s name in the walker
argument of wp_list_categories()
.
Procedurally Process Cateogries
Rather than having wp_list_categories()
echo out a list of categories, set the echo
argument to false
, set a variable to the function call’s return value, and use the PHP regular expression and string functions to modify the markup as needed.
The second solution can alternately be achieved by hooking into the wp_list_categories
filter, which receives the same generated markup as an argument that wp_list_categories()
returns when echo
is set to false
.