Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 将Walker导航菜单拆分为4列_Wordpress_Wp Nav Walker - Fatal编程技术网

Wordpress 将Walker导航菜单拆分为4列

Wordpress 将Walker导航菜单拆分为4列,wordpress,wp-nav-walker,Wordpress,Wp Nav Walker,我正在尝试将自定义mega菜单的子菜单部分拆分为四列。我使用下面的代码就快到了,但是,这只会将列分成两部分 我似乎尝试过每一种变化,但显然遗漏了一些东西。有什么帮助吗 class megamenu_panel extends Walker_Nav_Menu { var $current_menu = null; var $break_point = null; function start_lvl( &$output, $depth = 0, $args =

我正在尝试将自定义mega菜单的子菜单部分拆分为四列。我使用下面的代码就快到了,但是,这只会将列分成两部分

我似乎尝试过每一种变化,但显然遗漏了一些东西。有什么帮助吗

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 = 0, $args = array() ) {
        $indent = str_repeat("\t", $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 ), $item, $args ) );
        $class_names = ' class="' . esc_attr( $class_names ) . '"';

        $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $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, $item, $depth, $args );
    }
}
class megamenu\u面板扩展了Walker\u导航菜单{
var$current\u menu=null;
var$break_point=null;
函数start_lvl(&$output,$depth=0,$args=array()){
$indent=str\u repeat(“\t”,$depth);
$output.=“\n$indent
    \n”; } 函数end_lvl(&$output,$depth=0,$args=array()){ $indent=str\u repeat(“\t”,$depth); $output.=“$indent
\n”; } 函数开始(&$output、$item、$depth、$args){ 全局$wp_查询; 如果(!isset($this->current_菜单)) $this->current\u menu=wp\u get\u nav\u menu\u object($args->menu); 如果(!isset($this->break_point)) $this->break_point=ceil($this->current_menu->count/4)+1; $indent=($depth)?str_repeat(“\t”,$depth):”; $class_name=$value=''; $classes=空($item->classes)?array():(array)$item->classes; $classes[]=“菜单项-”。$item->ID; $class_name=join(“”,应用_过滤器('nav_menu_css_class',数组_过滤器($classes),$item,$args)); $class_names='class=“”.esc_attr($class_names)。”; $id=应用过滤器('nav_菜单项\u id','menu item-'。$item->id,$item,$args); $id=strlen($id)?'id=“”.esc_attr($id)。“:”; 如果($this->break\u point==$item->菜单顺序) $output.=$indent.
    ; 其他的 $output.=$indent.'; $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_输出=''; $item\u output.=$args->link\u before。应用\u过滤器('the\u title',$item->title,$item->ID)。$args->link\u before; $item_输出=''; $item_output.=$args->after; $output.=apply_filters('walker_nav_menu_start_el'、$item_output、$item、$depth、$args); } }
任何帮助都将不胜感激

非常感谢,,
SW

您也可以发布HTML输出吗?