I am trying to achieve something that seems like it should be simple but is causing me headaches. I am listing my categories out using wp_list_categories which gives me this…
<ul>
<li>Fruit</li>
<li>Vegetables</li>
<li>Tinned Goods</li>
<li>Dairy Products</li>
</ul>
All I want to do is add a class to the ul and li using a walker function, my function looks like this….
class Walker_Simple_Example extends Walker {
var $db_fields = array( 'parent' => 'parent_id', 'id' => 'object_id' );
function start_lvl(&$output, $depth=1, $args=array()) {
$output .= "\n<ul class=\"product_cats\">\n";
}
function end_lvl(&$output, $depth=0, $args=array()) {
$output .= "</ul>\n";
}
function start_el(&$output, $item, $depth=0, $args=array()) {
$output .= "<li class=\"item\">".esc_attr( $item->name );
}
function end_el(&$output, $item, $depth=0, $args=array()) {
$output .= "</li>\n";
}
}
This works fine for the li items and gives them all a class of ‘item’ but the ul class just doesn’t appear. Can anyone see where I am going wrong?