Hi all, was doing some searching through the site before I posted...
I'd like to know how to list all the categories and sub-categories in a static list.
I found this code below which Eric sorted for someone else a while ago, but it doesn't seem to work in V4 (I guess some table names have changed??)
Code:
To Implement the Menu ...
----------------------------------------------------------------------------------------
First create a new file named:
includes/classes/smarty/plugins/function.categories_ul.php
Then include this code:
<?php
/**
* smarty_function_categories_ul
*
* This function is useful for using your categories in the navigation.
*
* All source code & content (c) Copyright 2006, 68 Classifieds
* unless specifically noted otherwise.
*
* @package 68classifieds
* @author Eric Barnes
* @copyright 68 Classifieds
* @link http://www.68classifieds.com
* @$Revision: 1.1 $
* @Updated: $Date: 2007/01/08 19:12:22 $
*/
function smarty_function_categories_ul($params, &$smarty)
{
global $db;
$ul_attr = '';
$li_attr = '';
$depth=2;
$show_total = 'Y';
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'depth':
$$_key = (int)$_value;
break;
case 'ul_attr':
case 'li_attr':
case 'show_total':
$$_key = (string)$_value;
break;
}
}
$sSQL="SELECT id,name,parent_id,cOrder,cLink FROM ".PREFIX."categories WHERE parent_id=0 AND display<>'N' ORDER BY cORDER DESC, name ASC";
$result=$db->query($sSQL);
$output="<ul ".$ul_attr." class=\"menu\">\n";
while($row = $result->fetch())
{
$id=$row['id'];
$parent=$row['parent_id'];
if($row['cLink']<>'')
{
$link=$row['cLink'];
}
else
{
$link='category.php?type='.$id;
}
$output .= "<li ".$li_attr."><a class=\"topborder\" href=\"".$link."\">".$row['name']."</a>\n";
/*
if($show_total=='N')
{
$arr_childs='';
$arr_childs = array($id);
get_cat_ids($arr_childs);
$total=get_cat_count($arr_childs);
$output.="( ". $total .")";
}
*/
//get sub categories
$sSQL2="SELECT id,name,parent_id,cOrder,cLink FROM ".PREFIX."categories WHERE parent_id=".$id." AND display<>'N' ORDER BY cORDER DESC, name ASC";
//$output.=$sSQL2."\n";
$result2=$db->query($sSQL2);
if($result2->size() > 0)
{
$output.="<ul class=\"submenu\">\n";
while($row = $result2->fetch())
{
$subid=$row['id'];
if($row['cLink']<>'')
{
$link=$row['cLink'];
}
else
{
if($subid>1)
{
$link='category.php?type='.$id.'&sec='.$subid;
}
else
{
$link='category.php?type='.$subid;
}
}
$output .= "<li ".$li_attr."><a href=\"".$link."\">".$row['name']."\n";
if($show_total=='Y') {
$arr_childs = array($subid);
$total=get_cats($subid);
$output.="(". $total .")</a>";
}
}
$output.="</li>\n";
$output.="</ul>\n";
}
$output.="</li>\n";
}
$output.="</ul>\n";
return $output;
}
function get_cats($parent)
{
global $db;
$sSQL="SELECT id FROM ".PREFIX."categories WHERE parent_id = ". $parent;
//echo $sSQL;
$result=$db->query($sSQL);
$i=0;
while($rs=$result->fetch())
{
$cat[]=$rs['id'];
$i++;
}
if($cat == '')
{
$total=0;
}
else
{
$total=get_cat_count($cat);
}
return $total;
}
function get_cat_count($arr_ids)
{
global $db, $modules;
$sSQL="SELECT COUNT(*) AS size FROM ".PREFIX."products WHERE ".$where." section In (". implode(', ', $arr_ids) .") AND expiration > NOW() AND (display='Y' OR display='S')";
$result=$db->query($sSQL);
$row = $result->fetch();
$total=$row['size'];
return $total;
}
?>
Next in your template file add:
{categories_ul show_total='Y'}
any ideas on how to get it to work appreciated