WordPress.org

Ready to get started?Download WordPress

Forums

Display correct menu based on if it contains current page (2 posts)

  1. skinnytires
    Member
    Posted 2 years ago #

    + Admin creates a bunch of navigation menus via the appearance > menu admin screen.
    + These menus are not assigned to specific theme_locations. There could be dozens of these admin-created menus.
    + My single.php or single-customposttype.php would display the correct nav menu based on whether that nav menu contains the currently-viewed page.

    Ie: If nav menu contains a page with page id of this current page's $post_ID, then return the nav menu.

    Should I assume that I would use a custom walker that is passed the current page's ID as an argument?

    Then on my single.php or single-customposttype.php I'd use the wp_nav_menu() function with a "walker" argument pointing to this new walker object?

    If so, any thoughts on modifying a walker that would do this?

    Thank you!

  2. skinnytires
    Member
    Posted 2 years ago #

    For anyone who cares:

    + Use wp_nav_menu($args) like normal but with a custom walker
    + Within your custom walker, get the link's target page's id via $item->object_id and you should be good from there.

    Next up is to see if I can modify the admin menu page with any ease...

Topic Closed

This topic has been closed to new replies.

About this Topic