WordPress.org

Ready to get started?Download WordPress

Forums

wp_nav_menu => array (9 posts)

  1. cannon303
    Member
    Posted 3 years ago #

    Hi does anyone know how to output wp_nav_menu into a simple array rather than a string?

    Thanks

  2. Curtiss Grymala
    Member
    Posted 3 years ago #

    Probably the best way to do so is to define a custom "walker" for the nav menu; but I haven't done that yet, so I can't give much guidance on what the "walker" needs to do.

  3. esmi
    Forum Moderator
    Posted 3 years ago #

    Very crude:

    <?php
    $test = wp_nav_menu( 'echo=0' );
    $test = explode("\n", $test);
    ?>
  4. cannon303
    Member
    Posted 3 years ago #

    Curtiss Grymala yes I have no experience of "walker" either I'll have to see if i can learn it and esmi yup that seems to be the road i'm going down. My php is usually crude!

    Thanks for both of your replies, the quest continues....

  5. cannon303
    Member
    Posted 3 years ago #

    This is the third thread I've posted on this subject and completely drawn a blank, I can't believe this is so difficult!

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    wp_nav_menu() is a relatively new function and - unlike some of the older templating tags - it isn't built upon lower level functions that can be successfully re-used. A custom Walker class is definitely the best way to go but, like Curtiss, it's not something I've had reason to play with yet.

  7. cannon303
    Member
    Posted 3 years ago #

    yes I'm looking into walkers, it's very difficult to get my head round it especially as i can't see anyone asking the same question as i am in the context of walkers.

  8. cannon303
    Member
    Posted 3 years ago #

    Well I've pretty much exhausted every walker tutorial and forum query. There just isn't enough out there to help me with what i want.

    I wouldn't class myself as possessing a thorough and in depth knowledge of PHP being self taught, but can generally get by, however I'm no better equipped to grapple the concept of wordpress walkers and therefore no closer to my goal and have to admit defeat.

    There's a workaround function tutorial which I followed and that works how I want the menu to work. This doesn't work with any menus set up in admin=>appearance=>menus and doesn't work with wp_nav_menu() function but instead, uses the hierarchical structure of the old style parent attributes in the admin=> pages facility.

    It's a shame because my clients will understand the graphical nature of the menu editing facility and the drag and drop method and instead they will have to assign parents to sub pages and sub page parents to sub - sub pages via drop down menus and will have to give each page a numerical order ID to assign placement within the menu which is confusing to say the least.

    What a shame. I would like to leave this thread open please as I would like to crack this even if it is too late for this deadline.

  9. MastaBaba
    Member
    Posted 2 years ago #

    I had the same issue, implementing a Bootstrap-based design onto a WordPress template. My solution ain't elegant, but it works:

    [code moderated per forum rules- to share your solution, please use the pastebin]

Topic Closed

This topic has been closed to new replies.

About this Topic