WordPress.org

Ready to get started?Download WordPress

Forums

add submenu/ subnavigation to WordPress theme (5 posts)

  1. domoritz
    Member
    Posted 3 years ago #

    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
    http://codex.wordpress.org/Template_Tags/wp_nav_menu

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

  2. harmus
    Member
    Posted 3 years ago #

    Put $subMenuArray = array(); in your functions.php and add use this walker:

    http://pastebin.com/V57D1M3k

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

  3. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    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?

  4. nellisbasson
    Member
    Posted 3 years ago #

    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!

  5. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic