我正在努力实现一些看似简单但却让我头疼的事情。我正在使用wp\\U list\\U categories列出我的类别,这给了我这个。。。
<ul>
<li>Fruit</li>
<li>Vegetables</li>
<li>Tinned Goods</li>
<li>Dairy Products</li>
</ul>
我只想使用walker函数向ul和li添加一个类,我的函数如下所示。。。。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";
}
}
这对li项目很有效,并为它们提供了一个“项目”类,但ul类没有出现。有人能看出我错在哪里吗?