Hi, I would like output a hierarchical menu of my categories, but I'd like to output them in an template from a class in a different file. How is this is possible?
<?php
/*
+--------------------------------------------------------------------------
| sitemap.inc.php
| ========================================
| Displays a hierarchical view of categories.
+--------------------------------------------------------------------------
*/
if(!isset($config)){
echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
exit;
}
$sitemap= new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/sitemap.tpl");
class sitemaptree {
var $root_category_id = '0',
$max_level = '0',
$data = array(),
$root_start_string = '',
$root_end_string = '',
$parent_start_string = '',
$parent_end_string = '',
$parent_group_start_string = '<ul>',
$parent_group_end_string = '</ul>',
$child_start_string = '<li>',
$child_end_string = '</li>',
$spacer_string = '',
$spacer_multiplier = 1;
function sitemap() {
$db = new db();
$query = "SELECT cat_id, cat_name, cat_father_id FROM ".$glob['dbprefix']."CubeCart_category ORDER BY cat_father_id, cat_name, cat_id ASC";
$results = mysql_query($query);;
$this->data = array();
while ($categories = mysql_fetch_array($results)) {
$this->data[$categories['cat_father_id']][$categories['cat_id']] = array(
'id' => $categories['cat_id'],
'name' => $categories['cat_name'],
'count' => 0);
}
}
function buildBranch($cat_father_id, $level = 0) {
$result = $this->parent_group_start_string;
if (isset($this->data[$cat_father_id])) {
foreach ($this->data[$cat_father_id] as $category_id => $category) {
$category_link = $category_id;
$result .= $this->child_start_string;
if (isset($this->data[$category_id])) {
$result .= $this->parent_start_string;
}
if ($level == 0) {
$result .= $this->root_start_string;
}
$result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . '<a href="index.php?act=viewCat&catId='.$category['id'].'">';
$result .= $category['name'];
$result .= '</a>';
if ($level == 0) {
$result .= $this->root_end_string;
}
if (isset($this->data[$category_id])) {
$result .= $this->parent_end_string;
}
$result .= $this->child_end_string;
if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
$result .= $this->buildBranch($category_id, $level+1);
}
}
}
$result .= $this->parent_group_end_string;
return $result;
}
function buildTree() {
return $this->buildBranch($this->root_category_id);
}
}
$sitemap->assign("TXT_SITEMAP_TITLE",$lang['front']['sitemap']['title']);
[b]$sitemaptree = new sitemaptree;
$sitemap->assign("VAL_SITEMAP",$sitemaptree->buildTree());[/b]
$sitemap->parse("sitemap");
$page_content = $sitemap->text("sitemap");
?>
I have highlighted what I beleive the problem to be in bold, can anyone help me out?