Jump to content

Children of children listed by parent heading


Peter Knight
 Share

Recommended Posts

I have a new challenge - outputting the grandchild pages of 3 children (simple enough) but confine the display of each grandchild under it's parent heading.

Will try explain...

My tree looks like this:

Foods  (where I want to mirror the structure below in a table)

   - Fruit (Child of Foods and Level 2 Parent)
   - -  Apple 
   - -  Banana
   - -  Orange

   - Vegetable (Child of Foods and Level 2 Parent)
   - -  Carrot
   - -  Potato
   - -  Cauliflower

   - Meats (Child of Foods and Level 2 Parent)
   - -  Beef
   - -  Pork
   - -  Chicken

Lets say "Foods" is the parent.
Fruit, Veg and Meat are children.
Apple, Bananna etc are grand children

 

 

I have the Foods template working to an extent but it's doing the following. IE it's 

Fruit
- -  Apple
- -  Banana
- -  Orange
- -  Carrot
- -  Potato
- -  Cauliflower 
- -  Beef
- -  Pork
- -  Chicken

Vegetable
- -  Apple
- -  Bananna
- -  Orange
- -  Carrot
- -  Potato
- -  Cauliflower 
- -  Beef
- -  Pork
- -  Chicken

Meats
- -  Apple
- -  Bananna
- -  Orange
- -  Carrot
- -  Potato
- -  Cauliflower 
- -  Beef
- -  Pork
- -  Chicken

 

This is my effort so far.

<?php
		// the children of this page
		$products = $page->children();
		
		foreach ($products as $prod){
		
		// Create a table for each child page	
		echo"
			<div>
				<div class='prod-ov-wrapper'>
				
					<div class='prod-ov-text'>
					{$prod->title}
					
					<table class='uk-table uk-table-divider' border=1>
					<thead>
						<tr>
							<th>Part No.</th>
							<th>Length</th>
							<th>Break Force</th>
							<th>Width</th>
							<th>Colour</th>
						</tr>
					</thead>
					<tbody>
			";
					// populate the table with details of the children of each child	
					
					$proditem = $page->find("parent=$page->children, template=product"); 
					foreach ($proditem as $prodDetail){
						echo"
							<tr>
							<td>{$prodDetail->prod_partNo}</td>
							<td>{$prodDetail->prod_length}</td>
							<td>{$prodDetail->prod_breakForce}</td>
							<td>{$prodDetail->prod_width}</td>
							<td>{$prodDetail->title}</td>
							</tr>
							";}
				echo"			
						
						
					</tbody>
				</table>
					
					
					
					
					</div>
				</div>
			</div>
    		
			
		";}
		?>

 

I've tried a couple of things over the last few hours and just can't quite understand the API call I need at 

$proditem = $page->find("parent=$page->children, template=product"); 
foreach ($proditem as $prodDetail){
echo"

 

is there a way to do this? I suspect I am close but need to add another variable in there?

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...