最简单的方法是扩展Walker_Nav_Menu类而不是Walker_Class,(因为已设置了父/ ID字段,并且通常您希望维护某些标记等)。 主要方法是: start_el// end_el-负责显示列表中的元素 start_lvl/ end_lvl-负责显示子菜单 0) return parent::end_lvl(&$output, $depth); $output .= '
'; } // Start element function start_el(&$output, $item, $depth=0, $args=array()) { if( 0 == $depth ){ $output.= '

'.apply_filters( 'the_title', $item->title, $item->ID ).'

'; return; } // level 2+ parent::start_el(&$output, $item, $depth, $args); } // Don't need to add any output - sub menus aren't nested function end_el(&$output, $item, $depth=0, $args=array()) { if($depth > 0) parent::end_el(&$output, $item, $depth); } }