• Hello!

    I’m currently makeing a kind of menu on my wordpress installation looking something like this. (Its made of “pages”)
    Page
    – sub page
    – Sub sub page

    I’ve managed to get the first menu working. And the “sub page” to work. With the following code:
    <?php wp_nav_menu( array( ‘child_of’ => $post->ID , ‘depth’ => 1) ); ?>

    and it works perfectly fine. With that bit of code it just show the “sub page’s”.

    To explain abit further before my auctal problem:

    I first have a top menu that is made out of the “head pages”. Then I have a menu further down that show the “sub pages” depending on which “head page” I’m on and that works perfectly fine.

    But now I have another menu that I want to show depending on what “subpage” I’ve clicked on.

    I’ve tried the following code:
    <?php wp_nav_menu( array( ‘child_of’ => $post->ID , ‘depth’ => 2) ); ?>

    And it shows the “sub pages & the sub-subpages” but I just want to get the “sub-subpages”. I’ve googled like a freak but I can’t find any working solution at all.

    I’m sorry for the grammar but I hope you understand what I mean.

    ~ thanks, a new wordpress user
    Marcus

Viewing 7 replies - 1 through 7 (of 7 total)
  • Newbie here also…

    Are you aware of the “parent” selections available in the page editor? I will soon be doing what you are doing as far as pick-your-parent > child/children > sub-child/sub-children is concerned, and I plan to do that right there.

    Thread Starter stahla

    (@stahla)

    Head page
    -> Sub page (Parent: Head page)
    -> Sub sub page (Parent: sub page)

    Is how I use it. And there is alot of different pages in different categories but to simplify it.

    Hey Marcus,

    Not sure if you are using page templates for each of these or if you are trying to just dynamically insert the menu depending on what page they are landing on…

    You could try wp_list_pages(): specifically, depth and child_of rather than wp_nav_menu. If you use the page ID for the “sub page” level then it will display the menu items for “sub, sub page”. Also, to help with searching for solutions:

    “page”: = parent
    “sub pages” = child pages
    “sub, sub pages” = grand child pages

    Sorry if that doesn’t really answer, but I am ready for bed! ??

    Thread Starter stahla

    (@stahla)

    Okey I will check into that.

    To explain it abit more. I have a head menu at the top of the site there its 3 options.

    I refer to those as “head pages”. Each one of them have a own page template I’ve made with the code.

    Then I have a second menu that should show different options depending on what “head menu option” u have pressed. So far I’ve got it all works. (Those menu options to the second menu is made out of pages with the different head menus as parents). So a second menu have all the same templates as the head menu it refers to.

    Then the next thing is my sidemenu. That one should show when I’ve pressed on a menu option out of the second menu. (Those menu options to the “third/sidemenu” are made out of grandchild pages.

    So a grand child page have a second menu option page as the parent.

    So long I’ve come and with the code exampels before.

    Thread Starter stahla

    (@stahla)

    Okey I’ve come with it this far now!

    When I press a page (head page, no parent) then I show the childs of a that page in a middle menu as I call it. After that I show a big content div.

    Works perfectly fine with what I want.

    When I press one of the child pages I show the content of that child page and now I have a smaller content div and to the left of it a “submeny” containg menu options with the parents set to the “child of headpage” so its grandchildrens.

    That works absolutelty fine aswell.

    So far so good.

    But when I press one of the “grand child pages” in my submeny to the left of the content:

    Then I get the grandchildpages in my “middle menu” but the I still want to show the same as before.

    And my menu to the left dissapear.

    This is the following codes I have currently (and currently work on it will post a solution if I find it before anyone else):

    CODE FOR THE MIDDLE MENU: (I know its not fully optimized and that thes a few if's in it that not used currently but its just because I'm working with it and trying different approaces, will be fixed when its finished)
    
    <?
    $child_of_value = ( $post->post_parent ? $post->post_parent : $post->ID );
    $depth_value = ( $post->post_parent ? 1 : 1 );
    
    $wp_list_pages_args = array(
        'child_of' => $child_of_value,
        'depth' => $depth_value,
        'title_li' => 0
    );
    
    wp_list_pages( $wp_list_pages_args );
    ?>
    My sidebarmenu: (To the left of the content)
    <?php
    $wp_list_pages_args = array(
        'child_of' => $post->ID,
        'depth' => 2,
        'title_li' => 0
    );
    
    if ($post->ID == 14 || $post->ID == 16 || $post->ID == 9) {
    
    } else {
    	wp_list_pages( $wp_list_pages_args );
    }
    ?>

    And my “template file” code with these files:

    <?php if ($post->ID == 14 || $post->ID == 16 || $post->ID == 9) {?>
    				<div id="container-main-big">
    					<?php if (have_posts()) : ?>
    						<?php while (have_posts()) : the_post(); ?>
    						<h1><?php the_title();?></h1>
    						<?php the_content(); ?>
    					<?php endwhile;?>
    					<?php endif;?>
    
    				</div>
    				<? } else {?>
    
    				<div id="container-submenu" class="container-submenu-red">
    
    					<?php get_template_part( 'sidebar-menu'); ?> 
    
    				</div>
    				<div id="container-main">
    					<?php if (have_posts()) : ?>
    						<?php while (have_posts()) : the_post(); ?>
    						<h1><?php the_title();?></h1>
    						<?php the_content(); ?>
    					<?php endwhile;?>
    					<?php endif;?>
    
    				</div>
    				<div class="clear"></div>
    				<?}?>

    SO: Everything works until you hit the “grand child page”. Then the middle-menu shows the “other and this grand child page” but infact I want it to show the childpages still out of the current head page.

    And the menu to the left shows plain nothing, that one I instead want to show the grand child pages.

    Thread Starter stahla

    (@stahla)

    Okey so I finaly got everything to work as I wanted. Thought I share it.

    My sidebar menu:

    <?php
    /* Sidmenyn f?r alla f?rutom "grand child" */
    $wp_list_pages_args = array(
        'child_of' => $post->ID,
        'depth' => 2,
        'title_li' => 0
    );
    
    if ($post->ID == 14 || $post->ID == 16 || $post->ID == 9) {
    
    } else {
    	wp_list_pages( $wp_list_pages_args );
    }
    
    /* Grand child menyn */
    
    if( count(get_post_ancestors($post->ID)) == 2 ) {
    
    	$wp_list_pages_args2 = array(
    		'child_of' => $post->post_parent,
    		'depth' => 2,
    		'title_li' => 0
    	);
    
    	wp_list_pages( $wp_list_pages_args2 );
    	}
    ?>

    Container menu

    <?php
    	if($post->post_parent){
    		$parent = get_page($post->post_parent);
    			if($parent->post_parent){
    
    			$wp_list_pages_args = array(
    				'child_of' => $parent->post_parent,
    				'echo' => 0,
    				'depth' =>1,
    				'title_li' => 0
    			);
    			$children = wp_list_pages($wp_list_pages_args);
    
    			}else{
    
    			$wp_list_pages_args = array(
    				'child_of' => $post->post_parent,
    				'echo' => 0,
    				'depth' =>1,
    				'title_li' => 0
    			);
    			$children = wp_list_pages($wp_list_pages_args);
    
    			}
    	} else{
    
    	$wp_list_pages_args = array(
    		'child_of' => $post->ID,
    		'echo' => 0,
    		'depth' =>1,
    		'title_li' => 0
    	);
    		$children = wp_list_pages($wp_list_pages_args);
    	}
    	echo("<ul>");
    	echo $children;
    	echo("</ul>");
    	?>

    Nice job!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help to make a menu of grandchild pages’ is closed to new replies.