You don’t have the data you need in the start_lvl()
method to do this. That data is available in the start_el()
method in the $item
variable, so you will have to cook up a way to pass that data along:
class my_extended_walker extends Walker_Nav_Menu {
var $prnt = 0;
var $pdepth = false;
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$id = '';
if (!empty($this->prnt)) {
$id = 'id="prnt-'.$this->prnt.'"';
}
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul $id class=\"collapse\">\n";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
if ($this->pdepth !== $depth) {
$this->prnt = $item->ID;
$this->pdepth = $depth;
} else {
$this->prnt = $this->pdepth = 0;
}
parent::start_el($output,$item,$depth,$args,$id);
}
}
// testing
wp_nav_menu(
array(
'walker'=>new my_extended_walker(),
'menu' => 'mymenu'
)
);