【发布时间】:2015-07-15 23:41:51
【问题描述】:
我是 wordpress 新手,正在尝试构建一个自制的菜单结构。我找到了一个定制的助行器,并根据我的需要对其进行了定制。菜单运行良好,您现在可以在 my site 上看到。
它通过<?php wp_nav_menu(array('walker' => new Custom_Nav_Walker())); ?> 加载到 header.php 中。该命令嵌套在一个ul标签内,所以walker只生成里面的li标签。
现在我想向当前父菜单项添加一个名为active 的类,它是下拉子项。我在网上搜索了几个小时,但没有找到任何我能理解的内容……
_
谁能帮我将该类实现到我的自定义walker中?
提前致谢!
贾罗
class Custom_Nav_Walker extends Walker_Nav_Menu {
function start_lvl(&$output, $depth = 0, $args = array()) {
$output .= "";
}
function end_lvl(&$output, $depth = 0, $args = array()) {
$output .= "";
}
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
parent::start_el($item_html, $item, $depth, $args);
if ($item->is_dropdown && ($depth === 0)) {
$output .= "";
} elseif ($depth === 0) {
$output .= "<li class=\"navbar-list-item\"><div class=\"w-dropdown\" data-ix=\"dropdown\"><div class=\"w-dropdown-toggle navbar-link\"><h5>".esc_attr($item->title)."</h5></div><nav class=\"w-dropdown-list dropdown-list\">";
} elseif ($depth > 0) {
$output .= "<a class=\"w-dropdown-link dropdown-link\" href=\"".esc_attr($item->url)."\">".esc_attr($item->title)."";
}
}
function end_el(&$output, $item, $depth=0, $args=array()) {
if ($item->is_dropdown && ($depth === 0)) {
$output .= "";
} elseif ($depth === 0) {
$output .= "</nav></div></li>";
} elseif ($depth > 0) {
$output .= "</a>";
}
}
}
【问题讨论】: