[eluser]Federico BaƱa[/eluser]
Try something like this for the cateogry menu:
Code:
// Lets see..
/* here you'll store the categories with its children like this:
"0" = > [
"{cat_id}" => [
"name" => "{cat_name}",
"children" => [
"{cat_id}" => [
...
],
"{cat_id}" => [
...
]
]
],
"{cat_id}" => [
"name" => "{cat_name}",
"children" => [
"{cat_id}" => [
...
],
"{cat_id}" => [
...
]
]
]
]
*/
//
public $category_tree = array();
// this function will generate that list with the array you have now
// always considering you have the cats sorted by parent_id ASC
function generate_menu()
{
// define a root category with id 0 and store all the non-children cats inside
$root = array('children' => array());
$this->category_tree["0"] = $root;
// then go trough all the items in the array
foreach($this->categories as $c)
{
// and just add the current category as a child of its parent
// id the main array is sorted by parent_id asc, at the time of adding children categories we'll already have all the "root" categories stored inside our root array
$this->category_tree[ $c['parent_id'] ]['children'][] = $c;
}
// then remove the first level of the array as its useless from now on
$this->category_tree = $this->category_tree["0"];
}
hope this helps..
about the other recursives i cant figure out what you want to get there, what is $segs actually? (in the first method)