Peter Knight Posted June 14, 2017 Share Posted June 14, 2017 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 - - ChickenVegetable - - Apple - - Bananna - - Orange - - Carrot - - Potato - - Cauliflower - - Beef - - Pork - - ChickenMeats - - 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 More sharing options...
ottogal Posted June 14, 2017 Share Posted June 14, 2017 Have a look to the Cheatsheet to find ways of selecting determined parents of a page, from simpler ones to this smartest one: http://cheatsheet.processwire.com/page/built-in-methods-reference/page-parent-selector/ Link to comment Share on other sites More sharing options...
Peter Knight Posted June 14, 2017 Author Share Posted June 14, 2017 I have it working - thanks again @ottogal Eventually I stripped back everything and started again with this foreach($page->children as $category) { echo "... "; foreach($category->children as $prod) { echo " Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now