Skip to content

Instantly share code, notes, and snippets.

@mr-fan
Forked from somatonic/mylist.php
Created June 15, 2014 22:12
Show Gist options
  • Save mr-fan/e9a656079c0ece66abd0 to your computer and use it in GitHub Desktop.
Save mr-fan/e9a656079c0ece66abd0 to your computer and use it in GitHub Desktop.
<?php
$children = $pages->get("/shop/")->children();
$list = new PageArray();
function mylist($children, $ind='', $arr){
$ind .= "– ";
foreach($children as $cat) {
$countproducts = wire("pages")->find("template=product,categories=$cat")->count();
$cat->title = $ind . $cat->title . " ($countproducts)";
$arr->add($cat);
if($cat->numChildren) {
mylist($cat->children,$ind, $arr);
}
}
return $arr;
}
$result = mylist($children, $ind='',$list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment