Wordpress自定义助行器创建双菜单

Wordpress自定义助行器创建双菜单,wordpress,menu,jquery-isotope,Wordpress,Menu,Jquery Isotope,您好,我已经为我的wordpress主题设置了这个自定义walker,以显示我的主菜单。我大约在一个月前开始调整它,但后来一直在做一些其他的东西。回到这里,我有点不知道我离开的时候在哪里 目前我能看到的唯一真正的问题是,步行机正在生成一个双菜单。因此,每个链接显示两次 有人知道为什么菜单项会出现两次吗 这是定制步行器: class Custom_Walker_Nav_Menu extends Walker_Nav_Menu { function start_el(&$output

您好,我已经为我的wordpress主题设置了这个自定义walker,以显示我的主菜单。我大约在一个月前开始调整它,但后来一直在做一些其他的东西。回到这里,我有点不知道我离开的时候在哪里

目前我能看到的唯一真正的问题是,步行机正在生成一个双菜单。因此,每个链接显示两次

有人知道为什么菜单项会出现两次吗

这是定制步行器:

class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
        if ( $depth )
            $indent = str_repeat("\t", $depth);
        else
            $indent = '';

        extract($args, EXTR_SKIP);
        $linkName = apply_filters( 'the_title', $item->post_title, $page->ID );

        if($linkName=="HOME"){
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="all" data-filter=".all">'.$linkName.'</a>';
        }else{
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".'.strtolower($linkName).'">'.$linkName.'</a>';
        }

        if($linkName=="CONTACT"){
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="/contact" class="contact" data-filter=".all">'.$linkName.'</a>';
        }else{
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".'.strtolower($linkName).'">'.$linkName.'</a>';
        }
    }


    function end_el(&$output, $page, $depth = 0, $args = array()) {
                $output .= "</li>\n";
    }

}
类自定义导航菜单扩展了导航菜单{
函数start_el(&$output,$item,$depth=0,$args=array(),$id=0){
如果($深度)
$indent=str\u repeat(“\t”,$depth);
其他的
$indent='';
提取($args,EXTR_SKIP);
$linkName=apply_过滤器('the_title',$item->post_title,$page->ID);
如果($linkName==“主页”){
$output.=$indent.
  • ”; }否则{ $output.=$indent.
  • ”; } 如果($linkName==“联系人”){ $output.=$indent.
  • ”; }否则{ $output.=$indent.
  • ”; } } 函数end_el(&$output,$page,$depth=0,$args=array()){ $output.=“
  • \n”; } }

    谢谢,这是因为您还没有学会如何使用if循环。您有两个,因此将输出两个链接。您只希望输出1,以便:

    if($linkName=="HOME"){
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="all" data-filter=".all">'.$linkName.'</a>';
    } elseif($linkName=="CONTACT"){
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="/contact" class="contact" data-filter=".all">'.$linkName.'</a>';
    }else{
            $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".'.strtolower($linkName).'">'.$linkName.'</a>';
    }
    
    if($linkName==“HOME”){
    $output.=$indent.
  • ”; }elseif($linkName==“联系人”){ $output.=$indent.
  • ”; }否则{ $output.=$indent.
  • ”; }