简体   繁体   English

验证错误:流浪结束标签选项

[英]Validation error: Stray end tag option

I am getting the error: "Stray end tag option." 我收到错误消息:“流浪结束标记选项”。 and I can tell it's coming from my mobile menus. 我可以说它来自我的移动菜单。

For some reason my code is adding extra tags at the end. 由于某种原因,我的代码在末尾添加了额外的标签。 Here is a little preview of what the w3 validation site is showing me. 这是w3验证网站向我展示的内容的一些预览。

<option value="">— Single Post Layouts<option value="http://domain.com/mag/portfolio/future-semiotics/">—— Full Image Post</option></option></option>

The strange thing is that it is not adding it to every single option just a few. 奇怪的是,它并没有将其添加到每个选项中。

I have been searching in my code and I found this in the custom functions file. 我一直在搜索代码,并且在自定义函数文件中找到了它。

class gbx_Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {

function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth); // don't output children opening tag (`<ul>`)
}

function end_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth); // don't output children closing tag
}

function start_el(&$output, $item, $depth, $args) {
    $url = '#' !== $item->url ? $item->url : '';
    $item->title = str_repeat("—", $depth).' '.$item->title; 
    $output .= '<option value="' . $url . '">' . $item->title;
}

function end_el(&$output, $item, $depth) {
    $output .= "</option>"; // replace closing </li> with the option tag
}
}

Any help on what I need to change to fix this issue would be great. 我需要更改以解决此问题的任何帮助都将非常有用。

EDIT: This code is in my header.php I didn't know if it would help at all. 编辑:这段代码在我的header.php中,我根本不知道是否有帮助。

<div class="mobile-nav-holder visible-xs">
    <?php wp_nav_menu(array('theme_location' => 'main_navigation', 'container_class' => 'mobile-mainmenu', 'walker' => new gbx_Walker_Nav_Menu_Dropdown(),'items_wrap' => '<select><option selected>Navigation</option>%3$s</select>')); ?>
</div>

update your this function 更新您的此功能

function start_el(&$output, $item, $depth, $args) {
    $url = '#' !== $item->url ? $item->url : '';
    $item->title = str_repeat("—", $depth).' '.$item->title; 
    $output .= '<option value="' . $url . '">' . $item->title.'</option>';
}

and remove or not use function end_el(&$output, $item, $depth) 并删除或不使用function end_el(&$output, $item, $depth)

it will handle your output 它将处理您的输出

<option value="">— Single Post Layouts</option>
<option value="http://domain.com/mag/portfolio/future-semiotics/">—— Full Image Post</option>

You're doing it wrong. 你这样做是错的。 Format your output manually with indentation and you'll get this: 使用缩进手动设置输出格式,您将获得以下信息:

    <option value="">— Single Post Layouts
        <option value="http://domain.com/mag/portfolio/future-semiotics/">—— Full Image Post</option>
    </option>
</option>

This class is supposed to generate nested structure and options are not supposed to be nested like this 此类应生成嵌套结构,而选项不应这样嵌套

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM