最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Custom Nav Walker Trouble

programmeradmin0浏览0评论

I got a snippet for a custom nav walker online and it works fine for the main menu items. I can't figure out how to get it to work for the sub-menu items.

This is what i'm trying to achieve:

<ul class="uk-navbar-nav main-nav-links">
      <li href="index.php" class="uk-active"><a href="#">HOME</a></li>
      <li>
        <a class="nav-link dropdown-toggle" href="#">ABOUT</a>
        <div class="uk-navbar-dropdown main-nav-drop-down">
          <ul class="uk-nav uk-navbar-dropdown-nav main-nav-drop-down-nav">
            <li class="uk-active"><a href="#">Active</a></li>
            <li><a href="#">Item</a></li>
            <li><a href="#">Item</a></li>
          </ul>
        </div>
      </li>
      <li><a class="nav-link dropdown-toggle" href="#">PROGRAMMES</a>
        <div class="uk-navbar-dropdown main-nav-drop-down">
          <ul class="uk-nav uk-navbar-dropdown-nav main-nav-drop-down-nav">
            <li class="uk-active"><a href="#">Active</a></li>
            <li><a href="#">Item</a></li>
            <li><a href="#">Item</a></li>
          </ul>
        </div>
      </li>
      <li><a href="#">OUR IMPACT</a></li>
    </ul>

This is the walker function i have:

class Header_Nav_Walker extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth=0, $args=array(), $id = 0) {
    $object = $item->object;
    $type = $item->type;
    $title = $item->title;
    $description = $item->description;
    $permalink = $item->url;

  $output .= "<li class='" .  implode(" ", $item->classes) . "'>";

  if( $permalink && $permalink != '#' ) {
    $output .= '<a href="' . $permalink . '">';
  } else {
    //do nothing
  }

  $output .= $title;

  if( $permalink && $permalink != '#' ) {
    $output .= '</a>';
  } else {
    //do nothing
  }
}

How can i get my walker class to output the menu i'm trying to achieve. Please help, i'm new to WordPress development and will really appreciate any help i can get. Thanks in advance.

发布评论

评论列表(0)

  1. 暂无评论