WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying Subpages of Subpages in sidebar (Level 3 menu) (9 posts)

  1. pulk99
    Member
    Posted 5 years ago #

    hi,
    I'm trying to achieve the following structure:

    Mainmenu (always visible)

    Page 1
    Page 2
    Page 3

    Submenu (only visible if Page 1,2, or 3 has a subpage)

    Page 1.1 (subpage of Page 1)

    ok, that's easy with the example on the codex page: http://codex.wordpress.org/Template_Tags/wp_list_pages

    but now comes my headache, if the subpage 1.1 has also a subpage, it should show a third menu with this subpage (1.1.1), and still displaying the 2 other menus (main & submenu)

    Page 1.1.1 (subpage of Page 1.1)

    any ideas, how I could check if a current child page has another child page and display this?

  2. richarduk
    Member
    Posted 5 years ago #

    Not trying to be funny, but did you read this on the page you linked to? Does it not work?

    depth (integer)
    This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).

    * 0 - Pages and sub-pages displayed in hierarchical (indented) form (Default).
    * -1 - Pages in sub-pages displayed in flat (no indent) form.
    * 1 - Show only top level Pages
    * 2 - Value of 2 (or greater) specifies the depth (or level) to descend in displaying Pages.

    child_of (integer)
    Displays the sub-pages of a single Page only; uses the ID for a Page as the value. Defaults to 0 (displays all Pages).

  3. pulk99
    Member
    Posted 5 years ago #

    I'm not sure if you understood me correctly, so here is my code I use (the main menu (wich is not in the code below) is a simpe wp_list_pages in the header):

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <div id="columnOne">
    <ul>
    <!-- this is the sub menu -->
    <?php echo $children; ?>
    </ul>
    
    <ul>
    <!-- here should be the menu with subpages of subpages be placed -->
    </ul>
    </div><!--// end #columnOne //-->
    
    <?php } else { ?>
    
    <div id="columnOneFront">
    </div><!--// end #columnOneFront //-->
    
    <?php } ?>
  4. richarduk
    Member
    Posted 5 years ago #

    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");

    In the codex this is written as

    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');

    Don't know if that's got anything to do with it.

    Also I see no braces after your if statement

    <?php
    if($post->post_parent)
    $children = wp_list_p  ........
  5. pulk99
    Member
    Posted 5 years ago #

    ok, I'm almost there, with this construct I get the 3rd level displayed where and when I want it:

    <div id="columnOne">
    <h1 class="hideme">Subnavigation</h1>
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul id="submenu">
    <?php echo $children; ?>
    </ul>
    
    <?php
    if($post->post_parent)
    $subchildren = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0");
    if ($subchildren) { ?>
    <ul id="subsubmenu">
    <?php echo $subchildren; ?>
    </ul>
    
    <?php } else { ?>
    
    <?php } ?>	
    
    <?php } else { ?>
    
    <?php } ?>
    </div>

    you can see the code in action here: http://preview.tinyurl.com/6e9kx3

    the only problem left is, if you click now on the 3rd level page (the last link in the left sidebar), the submenu goeas away, but this should be still visible, of course.

  6. pulk99
    Member
    Posted 5 years ago #

    ok, I finally solved it with the fold page plugin, here is my working code:

    <ul>
    <!-- Top level navigation -->
    <?php  wswwpx_fold_page_list ('depth=1&&exclude=11,12&sort_column=menu_order&title_li='); ?>
    </ul>
    
    <!-- Sub level navigation -->
    <?php
    $g_page_id = $wp_query->get_queried_object_id();
    $ancestorIDs = _wswwpx_page_get_ancestor_ids($g_page_id);
    $grandParent = $ancestorIDs[1]; ?>
    <ul id="submenu">
    <?php wswwpx_fold_page_list("title_li=&depth=1&sort_column=menu_order&child_of=".$grandParent); ?>
    </ul>
    
    <!-- SubSub level navigation -->
    <?php
    $SubgrandParent = $ancestorIDs[2]; ?>
    <ul id="subsubmenu">
    <?php wswwpx_fold_page_list("title_li=&depth=1&sort_column=menu_order&child_of=".$SubgrandParent); ?>
    </ul>
  7. cmsme
    Member
    Posted 5 years ago #

    @ pulk99

    great! that works for me! amazing work.

    i have one question tho, how could i make it so the css on the Top Level Navigation remains active when i am navigated to a SubSub level page.

    that really would make my life complete.

    thanks!

  8. cmsme
    Member
    Posted 5 years ago #

    its ok, i worked it out. for anyone else curious, you just need to add "current_page_ancestor" class to your css.

    sweet

  9. aaronmoodie
    Member
    Posted 5 years ago #

    pulk99, your code works great! but how would you go about putting the subsubpage list on a page template instead of the sidebar?

    just using:

    !-- SubSub level navigation -->
    <?php
    $SubgrandParent = $ancestorIDs[2]; ?>
    <ul id="subsubmenu">
    <?php wswwpx_fold_page_list("title_li=&depth=1&sort_column=menu_order&child_of=".$SubgrandParent); ?>

    doesn't seem to work, and using examples from the Template Tags/wp list pages examples keeps showing the sub pages as well as the sub sub pages.

Topic Closed

This topic has been closed to new replies.

About this Topic