• Resolved dbybanez

    (@dbybanez)


    Hi, I’m having troubles implementing this using WP Nav Walker. I created a custom class that extends Walker_Nav_Menu but I can’t figure out how the Walker traversing works. Do you have any complex nav walker tutorials you could recommend? Thanks in advance ??

    What my goal is:
    Goal

    What I have done so far:
    Problem

    What I want to achieve:
    Achieve

    Pastebin (Custom Nav Walker class):
    https://pastebin.com/3p2QNZMm

    Pastebin (Markup):
    https://pastebin.com/rzHuYFQ3

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The walker class is setup to deal with one level at a time. If I’m understanding your illustrations correctly, you are trying to go with the nth element of every level at a time. The first level below 1 being 1.1, 1.2, 1.3, etc. The level below 1.2 would be 1.2.1, 1.2.2, 1.2.3, etc. Every element in a level would have the same parent. If you want any other organization than one level at a time, you either need to restructure your data or create a different sort of walk method.

    The base walker loops through all elements of a level before recursing to the next. You need one that recurses at every element. You can still extend Walker_Nav_Menu, but override the base Walker::walk() method to alter the underlying logic.

    Thread Starter dbybanez

    (@dbybanez)

    Sorry for replying late.

    Yes, I’m trying to create a custom walker with different logic when traversing through all elements. I have another question but I think I might create another topic for this. I need to determine if the element is the last child of the current parent element.

    Thread Starter dbybanez

    (@dbybanez)

    Okay, so I solved my problem using this link: https://wordpress.stackexchange.com/a/49005/91164 The example only shows how to add classes to the last child of its siblings. But want I want to do is to modify how the last child displays.

    Though this is the closest to what I’m looking for, I just had to modify some logics of this code.

    I also encountered some problems displaying the item title. What I did was, instead of using $item, I used $element in function display_element(). For example (retrieving the item’s url): $element->url instead of $item->url.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating complex navs using custom nav walker’ is closed to new replies.