WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multilevel page menu static on level2 and more (7 posts)

  1. expromo
    Member
    Posted 5 years ago #

    Hello everyone!

    I have googled this topic front and backwords and have not found a solution. The problem looks like this.

    I'm working with static-pages only.
    I have a top menu with depth=1 so it displays only the top level of menu.

    I have a menu on the side to display only the further levels so therefore it looks like this :
    $theid = gettheid();
    wp_list_pages('child_of=$theid');

    And I get a list I want but the problem is I only get it when I'm in the top page and when I go into one of the children the menu dissappears - logic.

    I want to menu to stay the same in all further levels of children so I would need something called top_page_id :D

    Any idea on how to do this would be GREAT!

  2. MichaelH
    Member
    Posted 5 years ago #

    Is this what you are wanting?

    For use in sidebar, display only top level Pages, but when viewing a Page that has children (or is a child) show only children of that parent
    When visiting main page, all top level pages are listed in the sidebar.
    When click on a top level page with no children, all top level pages are listed.
    When click on a top level page with children, just the children pages are listed.
    When click on a children page, just the children of that parent are listed.

    <?php
    $output = wp_list_pages('echo=0&depth=1&title_li=<h2>Top Level Pages </h2>' );
    if (is_page( )) {
      $page = get_query_var('page_id');
      if ($post->post_parent) {
        $page = $post->post_parent;
      }
      $children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
      if ($children) {
        $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h2>Child Pages</h2>');
      }
    }
    echo $output;
    ?>
  3. expromo
    Member
    Posted 5 years ago #

    You went one step too far.
    I just need the page to:
    a) display the children of top parent element on every level
    b) display nothing if there are no children - not display a full menu

    If you could please clarify this for me I would be very greatful.

    EXAMPLE:
    Main page
    |-Subpage 1
    |-Subpage 2

    Generates:

  4. Subpage 1
  5. Subpage 2
  6. When I'm in : Main page, Subpage 1, Subpage 2

    If there are no Subpages the list is empty.

  • MichaelH
    Member
    Posted 5 years ago #

    a) display the children of top parent element on every level

    Don't use the depth= parameter.

    b) display nothing if there are no children - not display a full menu

    Not sure what you are getting at there.

    Resource:
    wp_list_pages()

  • expromo
    Member
    Posted 5 years ago #

    Thank you for pointing out the resource - can't believe I missed it.
    The solution I was looking for was: List subpages even if on a subpage

  • chuckienorton
    Member
    Posted 5 years ago #

    quick question on same subject, how can you continue showing just those subpages of the main top page (in a sidebar) with a lot of sub levels. I got it working great up to 2 levels deep (see here: http://www.thebestcoffee.com/local/jones-coffee-roasters/biographys/). But if you click on that third level, it turns it into the second level.

    Does that make sense. Click the link above, and click "biographies/Mireya" and you'll see that it turns "mireya" into the main level.

    Thanks in advance!
    Chuck

  • chuckienorton
    Member
    Posted 5 years ago #

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags