Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Php 如何扩展WordPress Nav Walker将菜单分为两个菜单? 我试图定制WPNaviWalk把菜单分成两个菜单,这样我的标识就在中间。第一个菜单将有一个左浮动,我的第二个菜单将有一个右浮动_Php_Wordpress_Wp Nav Walker - Fatal编程技术网

Php 如何扩展WordPress Nav Walker将菜单分为两个菜单? 我试图定制WPNaviWalk把菜单分成两个菜单,这样我的标识就在中间。第一个菜单将有一个左浮动,我的第二个菜单将有一个右浮动

Php 如何扩展WordPress Nav Walker将菜单分为两个菜单? 我试图定制WPNaviWalk把菜单分成两个菜单,这样我的标识就在中间。第一个菜单将有一个左浮动,我的第二个菜单将有一个右浮动,php,wordpress,wp-nav-walker,Php,Wordpress,Wp Nav Walker,我之所以这样做是因为我正在为我的机构创建一个主题,以便在许多项目上重复使用 最初,如果没有子菜单项,下面的代码可以工作,但一旦有子菜单项,代码就会中断。以下是我目前掌握的代码: Class Split_Menu_Walker extends Walker_Nav_Menu { var $current_menu = null; var $break_point = 0; public function start_lvl( &$output, $depth = 0, $args =

我之所以这样做是因为我正在为我的机构创建一个主题,以便在许多项目上重复使用

最初,如果没有子菜单项,下面的代码可以工作,但一旦有子菜单项,代码就会中断。以下是我目前掌握的代码:

Class Split_Menu_Walker extends Walker_Nav_Menu {

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

public function start_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat( "\t", $depth );
    $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n";
}


function start_el(&$output, $item, $depth = 0, $args = array(), $id=0) {
    $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    global $wp_query;

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

    if($depth == 0){
      if( !isset( $this->break_point ) )
          $this->break_point = ceil( $this->current_menu->count / 2 ) + 1;
    }


    if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) {
        $output .= $indent . '<li role="presentation" class="divider">';
    } else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) {
        $output .= $indent . '<li role="presentation" class="divider">';
    } else if ( strcasecmp( $item->attr_title, 'dropdown-header') == 0 && $depth === 1 ) {
        $output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title );
    } else if ( strcasecmp($item->attr_title, 'disabled' ) == 0 ) {
        $output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>';
    } else {
        $class_names = $value = '';
        $classes = empty( $item->classes ) ? array() : (array) $item->classes;
        $classes[] = 'menu-item-' . $item->ID;

     if($depth == 0){
       $classes[] = 'lvl-1';
     }
     if($depth == 1){
       $classes[] = 'lvl-2';
     }

      $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
      if ( $args->has_children )
        $class_names .= ' dropdown';

    $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 ) . '"' : '';

    $image = attachment_url_to_postid(get_theme_mod( 'logo_image' ));
    $logo_src = wp_get_attachment_image_src($image, 'logo')[0];

    $sticky = attachment_url_to_postid(get_theme_mod( 'sticky_logo_image' ));
    $sticky_logo = wp_get_attachment_image_src($sticky, 'logo')[0];

    $logo_padding = get_theme_mod('logo_padding');

    $blogName = get_bloginfo( 'name' );

    if( $this->break_point == $item->menu_order )
        $output .= $indent . '</li></ul><ul class="nav navbar-nav nav-right"><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 );
   }
  }
}
类拆分菜单\u Walker扩展了Walker\u导航菜单{
var$current\u menu=null;
var$break_point=0;
公共函数start_lvl(&$output,$depth=0,$args=array()){
$indent=str\u repeat(“\t”,$depth);
$output.=“\n$indent
    \n”; } 函数start_el(&$output,$item,$depth=0,$args=array(),$id=0){ $indent=($depth)?str_repeat(“\t”,$depth):”; 全局$wp_查询; 如果(!isset($this->current_菜单)) $this->current\u menu=wp\u get\u nav\u menu\u object($args->menu); 如果($depth==0){ 如果(!isset($this->break_point)) $this->break_point=ceil($this->current_menu->count/2)+1; } 如果(strcasecmp($item->attr_title,'divider')==0&&$depth==1){ $output.=$indent.
  • ; }else if(strcasecmp($item->title,'divider')==0&&$depth==1){ $output.=$indent.
  • ; }else if(strcasecmp($item->attr_title,'dropdown header')==0&&$depth==1){ $output.=$indent.'
  • '.esc\u attr($item->title); }else if(strcasecmp($item->attr_title,'disabled')==0){ $output.=$indent.
  • ; }否则{ $class_name=$value=''; $classes=空($item->classes)?array():(array)$item->classes; $classes[]=“菜单项-”。$item->ID; 如果($depth==0){ $classes[]=“1级”; } 如果($depth==1){ $classes[]='lvl-2'; } $class_name=join(“”,应用_过滤器('nav_menu_css_class',数组_过滤器($classes),$item,$args)); 如果($args->有子项) $class_name.='dropdown'; $class_names='class=“”.esc_attr($class_names)。”; $id=应用过滤器('nav_菜单项\u id','menu item-'。$item->id,$item,$args); $id=strlen($id)?'id=“”.esc_attr($id)。“:”; $image=attachment_url_to_posted(获取主题_mod('logo_image')); $logo_src=wp_get_attachment_image_src($image,'logo')[0]; $sticky=attachment_url_to_posted(获取主题_mod('sticky_logo_image')); $sticky_logo=wp_get_attachment_image_src($sticky,'logo')[0]; $logo_padding=get_theme_mod('logo_padding'); $blogName=get_bloginfo('name'); 如果($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); } } }
可以试试递归吗?你能告诉我你是否解决了这个深度问题吗?可以试试递归吗?你能告诉我你是否解决了这个深度问题吗。