如何解决在HTML标记中保留Wordpress类nav_walker
我正在使用沃克类来为导航菜单提供所需的结构,但我也想保留现有的WordPress类。即使我为.=
使用了串联附加运算符($output
),WordPress类也已被完全替换。关于如何纠正的任何想法?谢谢
class Walker_Nav_Primary extends Walker_Nav_menu
{
function start_el(&$output,$item,$depth = 0,$args = [],$id = 0)
{
$postid = url_to_postid($item->url);
$thumbnail = get_the_post_thumbnail_url($postid);
if (array_search('menu-item-has-children',$item->classes) && $depth == 0) {
$output .= sprintf("\n<li class='topnavitem %s'><a href='%s' class=\"topnavtext\">%s</a> <span class='plus'><i class='fas fa-angle-down'></i></span>\n",(array_search('current-menu-item',$item->classes) || array_search('current-page-parent',$item->classes)) ? '' : '',$item->url,$item->title);
} elseif (array_search('menu-item-has-children',$item->classes) && $depth == 1) {
$output .= sprintf("\n<li class='productsnav %s'><a href='%s' class=\"productsnavtext\">%s</a><span class ='sub-plus'><i class ='fas fa-angle-down'></i></span>\n",$item->title);
} elseif ($depth == 2) {
$output .= sprintf("\n<li class='scooppooopnavitem %s'><div class='pictext'><img src='%s'/><a href='%s' class=\"scooppoooopnavtext\">%s</a></div>\n",$thumbnail,$item->title);
} else {
$output .= sprintf("\n<li class='topnavitem %s'><a href='%s' class=\"topnavtext\">%s</a>\n",$item->title);
}
}
function start_lvl(&$output,$depth)
{
$indent = str_repeat("\t",$depth);
if ($depth == 0) {
$output .= "\n$indent<ul class=\"nav-level-one\" role=\"submenu\">\n";
}
if ($depth == 1) {
$output .= "\n$indent<ul class=\"nav-level-two\" role=\"subsubmenu\">\n";
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。