boccio
03-19-2006, 11:09 AM
Here is a little hack to display subcategories in main category view. If you have a lot of subcategories, you probably won't display them in main navigation to keep the nav clear, so this can come very useful.
1. category_Main.tpl
Place the {SHOW_SUBCATEGORIES} tag somewhere inside the template, where you want subcategories shown. Preferebly at the top of the file, above or below the {CATEGORY_NAME} tag. Format the output at will.
<tr>
<td colspan="2"><br />{SHOW_SUBCATEGORIES}</td>
</tr>
2. index.php:
Place the call to function that parses the new tag in template. Preferably somewhere around line 286:
$show_subcategories_HTML = HTML_show_subcategories($cid);
Also, around line 792, (at the bottom of the section after ''/{SITEMAP_LINK}/'') place this line:
'/{SHOW_SUBCATEGORIES}/',
and after line 836 (exactly after $sitemap_link,):
$show_subcategories_HTML,
3. HTML_function.php:
After line 161 (approx.) place the function to manage the display:
function HTML_show_subcategories($cid, $prf='')
{
global $url, $tpl_folder,$lang, $connection, $category;
$query = "SELECT id FROM tblCategories WHERE parent_cat=$cid ORDER BY order_num";
$result2 = mysql_query($query) or sql_error ($query, "show_subcategories");
$sub_category_menu = "";
while($row2=mysql_fetch_array($result2))
{
$sub_category = new Category();
$sub_category->LoadFromDatebase($connection,$row2['id']);
$sub_category_menu.= "<div class=\"category_link_depth2\"><a href=\"".HTML_show_friendly_cat($sub_category->Id)."\">";
$sub_category_menu.= $prf.$sub_category->Category_name."</a></div>";
$cid = $sub_category->Id;
$sub_category_menu.= HTML_show_subcategories($cid, $prf.'- ');
}
return $sub_category_menu;
}
1. category_Main.tpl
Place the {SHOW_SUBCATEGORIES} tag somewhere inside the template, where you want subcategories shown. Preferebly at the top of the file, above or below the {CATEGORY_NAME} tag. Format the output at will.
<tr>
<td colspan="2"><br />{SHOW_SUBCATEGORIES}</td>
</tr>
2. index.php:
Place the call to function that parses the new tag in template. Preferably somewhere around line 286:
$show_subcategories_HTML = HTML_show_subcategories($cid);
Also, around line 792, (at the bottom of the section after ''/{SITEMAP_LINK}/'') place this line:
'/{SHOW_SUBCATEGORIES}/',
and after line 836 (exactly after $sitemap_link,):
$show_subcategories_HTML,
3. HTML_function.php:
After line 161 (approx.) place the function to manage the display:
function HTML_show_subcategories($cid, $prf='')
{
global $url, $tpl_folder,$lang, $connection, $category;
$query = "SELECT id FROM tblCategories WHERE parent_cat=$cid ORDER BY order_num";
$result2 = mysql_query($query) or sql_error ($query, "show_subcategories");
$sub_category_menu = "";
while($row2=mysql_fetch_array($result2))
{
$sub_category = new Category();
$sub_category->LoadFromDatebase($connection,$row2['id']);
$sub_category_menu.= "<div class=\"category_link_depth2\"><a href=\"".HTML_show_friendly_cat($sub_category->Id)."\">";
$sub_category_menu.= $prf.$sub_category->Category_name."</a></div>";
$cid = $sub_category->Id;
$sub_category_menu.= HTML_show_subcategories($cid, $prf.'- ');
}
return $sub_category_menu;
}