WordPress.org

Ready to get started?Download WordPress

Forums

keep complete pagelist when last level is selected (2 posts)

  1. katootje
    Member
    Posted 7 years ago #

    on http://www.bronwasserwebsites.sohosted.com/wordpress I have made a submenu using some tips from this supportforum. The first levels are working okay, but with the last level the problem starts. Ón the website, the topmenu are links to pages. When you select 'Gebied', a submenu shows in the sidebar. This are the subpages of 'Gebied'. When you select one of the items, 'A2' you come to the next level: the subpages of A2. So far so good. 'Gebied' in the toplevel is still in a different color, the complete tree of the submenu is still there. But then, when you select one of the last items, the tree will disappear. The title above the submenu will change from 'Gebied' to A2 and only the last level will show in the list.
    I think it has something to do with the code I'm using, which is talking about parents and children. And of course, this are parents and children, but on the last level, the children become parent. In the fold_page_list.php I found ancestors, but I can't figure out how to use them in the code. The website of the plugin tells about far more levels then I'm using, so the thrick must be in this piece of code (I think)
    This is the code I use for the submenu:

      <?php
      global $wp_query;

      if( empty($wp_query->post->post_parent) ) {
      $parent = $wp_query->post->ID;
      $parent_title = $wp_query->post->post_title;
      } else {
      $parent = $wp_query->post->post_parent;
      $parent_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = $parent");
      }

      ?>

      <h2><?php echo apply_filters('the_title', $parent_title); ?></h2>
      <?php wswwpx_fold_page_list("sort_column=menu_order&title_li=&child_of=$parent_id&depth=$depth"); ?>

    I've tried some things myself, but the best result I got was a complete foldout submenu, also including the mainpages from the topmenu.
    How do I get the menu with grandparents, parents, children.]
    And of course, when selecting the last level, the menu-item in the topmenu must stay selected. I've added a current_page_ancestor line to the stylesheet, in line with the current_+page_item and the current_page_parent, but the ancestor isn't recognised I guess.

    Hope someone can help me out here. I've been looking for days now, trying to figure out how the code works. But my knowlegde is lacking here

  2. katootje
    Member
    Posted 7 years ago #

    We have solved this problem for a great deal.
    This is the code we made:

    <?php
    global $wp_query;

    if( empty($wp_query->post->post_parent) ) {
    $parent = $wp_query->post->ID;
    $parent_title = $wp_query->post->post_title;
    } else {
    $parent = $wp_query->post->post_parent;
    $temp = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID = $parent");
    if(empty($temp )){
    $parent = $wp_query->post->post_parent;
    $parent_title =$wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = $parent");
    }else{
    $parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID = $parent");
    $parent_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = $parent");
    }
    }

    ?>
    <h2><?php echo apply_filters('the_title', $parent_title); ?></h2>
    <?php wswwpx_fold_page_list("sort_column=menu_order&title_li=&child_of=$parent"); ?>

    We added the $temp to find out if the parent is only parent or also child.
    It works so far, that the submenu stays complete. But there is a mainmenu at the top of the site and when the last level in the submenu is reach, the mainpage in the topmenu is no longer recognised as current_page and so no longer in a different color. Solutions to solve that are more then welcome.

Topic Closed

This topic has been closed to new replies.

About this Topic