• Hello,

    i want to create a menu with 3 levels but dont know how to do this.

    The first menu level is the top navigation which needs to be visible always. When a user now clicks on one of these menu-items i want to display (if there is some) the sub pages (at a different place on the webiste, not as dropdown).

    Next i need to have a 3rd menu level which should be displayed on a different place when the user clicks on an item in the 2nd level menu.

    The important thing is, that the second level menu should be visible during the display of its child items. I dont want to have it get hidden when a user selects one element in the 2nd menu level.

    i have created an image which should visualize this. Hope it helps. Could someone help?

    regards
    Yavuz

Viewing 10 replies - 1 through 10 (of 10 total)
  • Can you use widgets? Is there a plugin that can manage that? My pal J. Michael Ambrosio (ambrosite) can achieve it for you; build a custom plugin. [link moderated]

    Thread Starter starcoder

    (@starcoder)

    No, i would like to achieve this via the WordPress Template Tags and Functions in my custom Theme.

    Thread Starter starcoder

    (@starcoder)

    How can i save the id of the item on which the user has clicked in the 2nd Menu? And how to know that this selected id comes from the 2nd Level?

    Thread Starter starcoder

    (@starcoder)

    Ok, what i could do is the folloowing:

    I would display the first level menu via:

    wp_list_pages('title_li=&sort_column=menu_order&depth=1&exclude=9,10,11');

    The second level could be displayed with:

    if($post->post_parent)
              $children = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0&sort_column=menu_order");
         else
              $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
    
         if ($children) { ?>
              <ul>
    <?php echo $children; ?>
              </ul>
    
         <?php } ?>

    Now the problem:

    I could display the third menu level with:

    <?php
    	  $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
    
              if ($children) { ?>
    	  <ul>
              <?php echo $children; ?>
              </ul>
         <?php } ?>

    But the, when i click on the first level menu i get the same result as in the 2nd level menu.

    How can i detect that i am in the second level? And if yes -> then show 3rd level menu else do not show 3rd level menu.

    regards
    Yavuz

    Thread Starter starcoder

    (@starcoder)

    Noone an idea?

    if($post->post_parent) {
        $siblings = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0&sort_column=menu_order");
        $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
    } else {
        $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
        $siblings = array();
    }
    
    if($siblings) {
    	//Output menu 1
    }
    if($children) {
    	//output menu 2
    }

    Could even be cut to!

    $siblings = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0&sort_column=menu_order");
    $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
    if($siblings) {
    	//Output menu 1
    }
    if($children) {
    	//output menu 2
    }

    HTH

    David

    Thread Starter starcoder

    (@starcoder)

    Great! Thank you very much!

    Thread Starter starcoder

    (@starcoder)

    hmm, i have tried it but it works for a 2 level menu design. i have 3 levels.

    = LEVEL1 =  = LEVEL 2 = = LEVEL 3 =
    PRODUCTS -> PRODUCT1 -> OVERVIEW
                         -> SCREENSHOTS
                         -> DOWNLOADS 
    
             -> PRODUCT2 -> OVERVIEW
                         -> SCREENSHOTS
                         -> DOWNLOADS

    What i need to have is:

    First i have only the Level1 shown on my page. For example user clicks on PRODUCTS, the page looks for children. It has children (PRODUCT1 and PRODUCT2) and show them inside an div.

    Then the user selects PRODUCT1 from LEVEL 2 and the page show LEVEL 1 -> PRODUCTS, LEVEL 2 PRODUCT1 and PRODUCT 2 and if LEVEL 2 hsa childrens too (in this case OVERVIEW, SCREENSHOTS, …) it shows these menu (pages) items, too WITHOUT HIDING THE LEVEL 1 and LEVEL 2 menu elements.

    First it looks like:
    PRODUCTS

    Then User clicks on PRODUCTS and i want to have

    PRODUCTS (to display in div1)
    
    PRODUCT1     PRODUCT2 (to display in div2)

    Then User clicks on PRODUCT1 and i want to have

    PRODUCTS (to display in div1)
    
    PRODUCT1     PRODUCT2 (to display in div2)
    
    OVERVIEW     SCREENSHOTS     DOWNLOADS (to display in div3)

    The menu levels should be displayed always. By default wordpress displays always the children and hides the parents/grandparents.

    How could i realize this?

    $parents = wp_list_pages("title_li=&depth=1&echo=0&sort_column=menu_order");
    if($post->post_parent) {
        $siblings = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0&sort_column=menu_order");
        $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
    } else {
        $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0&sort_column=menu_order");
        $siblings = array();
    }
    if($parents) {
    	//Output menu 1
    }
    if($siblings) {
    	//Output menu 2
    }
    if($children) {
    	//output menu 3
    }

    HTH

    David

    Thread Starter starcoder

    (@starcoder)

    thank you! ok, i have implemented it but found one bug:

    when you click on menu 1 -> menu 2 is getting displayed -> ok
    when you click on menu 2 -> menu 3 is getting displayed and you see menu 1 -> ok
    when you click on menu 3 -> menu 2 gets hidden!

    Update…
    But one more thing, i see that the problem in a real project would be that i have one time the siblings as children of menu1 and one time i have the children as the children of menu 1.

    I dont think that this seems to be possible with out of the box template tags.

    I think will do own DB-Queries to this to work.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Menu with 3 Levels’ is closed to new replies.