WordPress自定义Walker类获取子菜单的姊妹页
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress自定义Walker类获取子菜单的姊妹页相关的知识,希望对你有一定的参考价值。
No modifications or testing carried out yet.
/** * Custom Walker to extract current sub-menu */ class Custom_Walker_Nav_Sub_Menu extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { global $wp_query; //this only works for second level sub navigations $parent_item_id = 0; $class_names = $value = ''; $class_names = ' class="' . esc_attr( $class_names ) . '"'; $output.= ' <li>'; } // Checks if the current element is in the current selection // Keep track of all selected parents $this->found_parents[] = $item->ID; //check if the item_parent matches the current item_parent if($item->menu_item_parent!=$parent_item_id){ $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; $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 ); } } } function end_el(&$output, $item, $depth) { // Closes only the opened li $output .= "</li> "; } } function end_lvl(&$output, $depth) { // If the sub-menu is empty, strip the opening tag, else closes it } else { $output .= "$indent</ul> "; } } }
以上是关于WordPress自定义Walker类获取子菜单的姊妹页的主要内容,如果未能解决你的问题,请参考以下文章
wp_nav_menu walker 类子菜单仅显示在父页面上
添加一个 div 并使用 wordpress walker 更改类或导航菜单?
php Wordpress菜单/导航----将.active类添加到活动菜单项---- Bootstrap Nav Walker