将Walker Nav菜单拆分为4列

问题描述

我正在尝试将自定义超级菜单的子菜单部分分为四列。我几乎在下面的代码中使用该代码,但是,这只会将这些列分为两部分。

我似乎已经尝试了所有变体,但显然缺少一些东西。有帮助吗?

class megamenu_panel extends Walker_Nav_Menu {

    var $current_menu = null;
    var $break_point  = null;

    function start_lvl( &$output,$depth = 0,$args = array() ) {
        $indent = str_repeat("\t",$depth);
        $output .= "\n$indent<div class='megamenu-panel'><div class='megamenu-lists'><ul class='megamenu-list list-col-4'>\n";
    }
    function end_lvl( &$output,$depth);
        $output .= "$indent</ul></div></div>\n";
    }

    function start_el(&$output,$item,$depth,$args) {

        global $wp_query;

        if( !isset( $this->current_menu ) )
            $this->current_menu = wp_get_nav_menu_object( $args->menu );

        if( !isset( $this->break_point ) )
            $this->break_point = ceil( $this->current_menu->count / 4 ) + 1;    

        $indent = ( $depth ) ? str_repeat( "\t",$depth ) : '';

        $class_names = $value = '';

        $classes = empty( $item->classes ) ? array() : (array) $item->classes;
        $classes[] = 'menu-item-' . $item->ID;

        $class_names = join( ' ',apply_filters( 'nav_menu_css_class',array_filter( $classes ),$args ) );
        $class_names = ' class="' . esc_attr( $class_names ) . '"';

        $id = apply_filters( 'nav_menu_item_id','menu-item-'. $item->ID,$args );
        $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';

        if( $this->break_point == $item->menu_order )
            $output .= $indent . '</ul><ul class="megamenu-list list-col-4"><li' . $id . $value . $class_names .'>';
        else
            $output .= $indent . '<li' . $id . $value . $class_names .'>';

        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
        $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
        $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

        $item_output = $args->before;
        $item_output .= '<a'. $attributes .'>';
        $item_output .= $args->link_before . apply_filters( 'the_title',$item->title,$item->ID ) . $args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el',$item_output,$args );
    }
}

任何帮助将不胜感激。

非常感谢, SW

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...