【发布时间】:2013-12-19 06:27:24
【问题描述】:
我想在 WordPress 的导航子菜单中添加一个<li class="divider"></li>。那是在我要添加此<li> 的每个子菜单项之间。目前我正在使用 Walker_Nav_Menu 来显示使用
class Menu_With_Description extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->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 .= '<br /><span class="sub-text">' . $item->description . '</span>';
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown-menu\">\n";
}
}
我还将子菜单类更改为“下拉菜单”。我还想将<li class="dropdown"> 中的<a> 类更改为<a href="#" class="dropdown-toggle" data-toggle="dropdown">。所以我想要的菜单结构是
<ul class="nav navbar-nav">
<li><a href="link1.html">link1<br>
<span class="sub-text">text here<span> </a></li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">link2<br>
<span class="sub-text">text 2<span></a>
<ul class="dropdown-menu">
<li><a href="link3.html">link3</a></li>
<li class="divider"></li>
<li><a href="link4.html">link4</a></li>
<li class="divider"></li>
<li><a href="link5.html">link5</a></li>
</ul>
</li>
</ul>
请帮忙。
【问题讨论】:
标签: wordpress