WordPress.org

Ready to get started?Download WordPress

Forums

wp_nav_menu children subnavigation on page (4 posts)

  1. pixelschupser-nw
    Member
    Posted 1 year ago #

    Hey Folks!

    I've been using wp_list_pages to display the current page's childpages in the sidebar.
    It works great for pages that only have other pages as a child, but for our new project i need a different solution.

    Our main navigation mostly consists of pages, but there're also post categories and custom post type items.
    Let's say there's a parent page called "about", it's child pages are three normal pages and one post category, all assembled in the theme's menu settings page.

    If i'm using wp_list_pages now, i only get the three child pages of the parent, not the category.
    I need a way to read the active wp_nav_menu parent and display it's child items, whether pages or categories.

    I have no clue if this is possible, help would be much appreciated.
    Thanks!

  2. inhouse
    Member
    Posted 1 year ago #

    I found your post while searching for the same exact requirements. I wondered if there was a way to show the wp_nav_menu children of the current page. Seems like it'd be difficult to do but I'm still searching. I have a menu where it is common to have categories instead of pages so the wp_list_pages shows nothing in my child menu of course.

  3. pixelschupser-nw
    Member
    Posted 1 year ago #

    Hey inhouse,

    did you find a solution to our problem?

    Still havent's found anything personally.
    Any ideas of how this could be accomplished?

  4. inhouse
    Member
    Posted 1 year ago #

    Hi pixelschupser-nw, I ended up just using a second instance of the wp_nav_menu in my page template and then hiding the top level pages via CSS. Hide the "container-class ul li" with display:none and then for "container-class ul ul li" use display:block. That or use the current-menu-item class and the sub-menu. I pasted some CSS below. Let me know if you need more help.

    wp_nav_menu( array( 'container_class' => 'child-menu', 'theme_location' => 'main-menu' ) );
    .child-menu ul li {display:none;}
    .current-menu-item ul li {display:block;} (or inline-block depending on your design)

Topic Closed

This topic has been closed to new replies.

About this Topic