|
lsu
|
 |
« inserita:: 11 Agosto 2011, 14:59:37 » |
|
Hello,
In category view we wanted to see the total of books in each category including its subcategories. Therefor I extended the default.php template files of the category and categories by removing this
(<?php echo $row->numero; ?>)
and adding this
(<?php $numero = $row->numero; $depth = 0; $parents[$depth] = $row->id; /* Count the total number of books, including subcategories */ /* This method only works because the tree is sorted */ foreach($rows as $rownum) { $couldbeachild = true; while ($couldbeachild) { /* Is it a children? */ if ($rownum->parent_id == $parents[$depth]) { /* Yes, its a child, add the number of books*/ $numero += $rownum->numero; /* Assume there is are child item(s) inside, increase depth... */ $depth++; $parents[$depth] = $rownum->id; break; } elseif ($depth == 0) $couldbeachild = false; else $depth--; } } echo $numero; ?>)
Would be cool if this code could be included into the upstream version. Also it may be necessary to add a option for this feature (should be easy, just put an if around the whole for loop)
Bye Stefan
|