• Hi

    I want to add a submenu of a wordpress menu into my theme. I want to use the wp_nav_menu function of WordPress 3.0. And in other words, I want to see the submenu not the subpages which means that wp_list_pages is not the right function because I want the submenu and not the subpages.

    Let’s assume the menu structure looks like that:

    – Home
    – Entry1
    — Entry3
    — Entry4
    – Entry2
    — Entry5
    — Entry6

    I want that if someone clicks on Entry1 (and makes it the parent) the Theme just shows the submenu of this entry. In the case of Entry1 it’s:

    – Entry3
    – Entry4

    I know that there is a code like that:

    <?php
            $children = ($post->post_parent) ? wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') : wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
            if($children) { echo('<ul>'.$children.'</ul>'); }
         ?>

    However, the point is that I’m talking about the menu structure and not the page structure. Oh, and the depth parameter does not work because it means to here and not from here.

    I think there could be a solution with a custom walker but I don’t know how to implement that.

    Function reference for wp_nav_menu
    https://codex.www.ads-software.com/Template_Tags/wp_nav_menu

    I’m looking for a solution for this problem for so long so please help me. Thanks a lot.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Put $subMenuArray = array(); in your functions.php and add use this walker:

    https://pastebin.com/V57D1M3k

    It’ll get your submenu’s in an array ($subMenuArray), ordered by the id of the parent item.

    Does your menu have things other than Pages in it (or is your menu structured other than your Parent-Child Page relationships), such that wp_list_pages() wouldn’t work for you?

    Where does one change the way it looks then? Have been struggling with this forever. It doesn’t matter what I do or where I change it, it keeps showing as a list, thats underlined. how does one put it next to one another?

    Thank you so much in advance!

    @nellisbasson: yours sounds like a separate issue. You should start a separate thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add submenu/ subnavigation to WordPress theme’ is closed to new replies.