Forums

How do I know if a menu item has children or is a leaf? (3 posts)

  1. otikik
    Member
    Posted 5 months ago #

    Hi there!

    I'm developing a new theme and I need to mark menu items without children differently from "leaf" (no children) ones. Ideally with a css class for the "parents" - has-children, or similar. This is how my walker code looks now:


    class My_Walker_Nav_Menu extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth, $args) {
    ...
    if(??? $item has children???) {
    // I know what to do here
    }
    }
    }

    What should I put between the ???s ?

    Thanks and regards!

    PS: This question is also in StackOverflow and has a bounty of 100 rep points. Please feel free to answer there and I will gladly grant you those points.

  2. keesiemeijer
    moderator
    Posted 5 months ago #

  3. otikik
    Member
    Posted 5 months ago #

    Hmm. I see. So he can't do it in start_el, he uses the display_element instead. That looks like a possible answer. Thanks!

    PS: please feel free to post that link to the SO question as an answer.

Reply

You must log in to post.

About this Topic