沃克菜单,在下拉菜单中获取父元素,在另一个元素中获取子元素

walker menu, get parent element in a dropdown and child element in another element

这是我的情况,我正在尝试自定义 wordpress 菜单:

到目前为止我的学步车是这样的:

  class My_Walker_Nav_Menu_language extends Walker_Nav_Menu {

function start_el(&$output, $item, $depth, $args) {
    $url = '#' !== $item->url ? $item->url : '';
    $output .= '<option value="' . $url . '">' . $item->title;
}   
function end_el(&$output, $item, $depth){
    $output .= "</option>\n$indent"; // replace closing </li> with the option tag
}

}

问题是,它是在同一个 select 下拉列表中添加父元素和子元素,而不是两个分开的元素。 .

如何实现?

能得到一些帮助就太好了,

谢谢

-- 编辑--

示例:

如果我有这样的菜单:

<ul id="menu-network-menu" class="menu">
<li id="menu-item-537" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children YO menu-item-537">
    <a href="#">Europe</a>
    <ul class="sub-menu">
        <li id="menu-item-538" class="blog-id-4 mlp-language-nav-item menu-item menu-item-type-language menu-item-object-mlp_language menu-item-538">
            <a rel="alternate" href="http://mysite.local/fr/?noredirect=fr_FR">
                 French FR</a>
        </li>
        <li id="menu-item-542" class="blog-id-1 mlp-language-nav-item menu-item menu-item-type-language menu-item-object-mlp_language mlp-current-language-item menu-item-542">
            <a rel="alternate" href="http://mysite.local/">
                English (UK)</a>
        </li>
    </ul>
</li>
<li id="menu-item-541" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children YO menu-item-541">
    <a href="#">America</a>
    <ul class="sub-menu">
        <li id="menu-item-539" class="blog-id-5 mlp-language-nav-item menu-item menu-item-type-language menu-item-object-mlp_language menu-item-539">
            <a rel="alternate" href="http://mysite.local/cr/?noredirect=es_CO">
                 CR</a>
        </li>
    </ul>
</li>
<li id="menu-item-540" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children YO menu-item-540">
    <a href="http://Asia">Asia</a>
    <ul class="sub-menu">
        <li id="menu-item-543" class="blog-id-6 mlp-language-nav-item menu-item menu-item-type-language menu-item-object-mlp_language menu-item-543">
            <a rel="alternate" href="http://cn.mysite.local/?noredirect=zh">
                 China</a>
        </li>
    </ul>
</li>

<select>
<option>EUROPE</option
<option>AMERICA</option
<option>ASIA</option
</select>

<select>
<option>French FR</option
<option>English (UK)</option
<option> CR</option
<option>China</option
</select>

据我所知,您想将所有菜单更改为 select 下拉菜单,如果我理解正确,您提出问题,那么这里是工作功能:

class My_Walker_Nav_Menu_language  extends Walker_Nav_menu {


public  function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ){ //li a span
$url = '#' !== $item->url ? $item->url : '';

if ($item->menu_item_parent == 0){ 
$output .= '<select><option value="' . $url . '">' . $item->title;
}
$output .= ' <option value="' . $url . '">' . $item->title;

}
function end_el(&$output, $item, $depth = 0, $args = Array()){ // closing li a span
if ($item->menu_item_parent == 0){ 
$output .= "</option></select> "; // replace closing </li> with the option tag
}
$output .= "</option>"; // replace closing </li> with the option tag
}

}