PDA

View Full Version : Display subcategories on Category page


boccio
03-19-2006, 12:09 PM
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;
}

Frankc2
05-25-2006, 04:29 PM
Is this instructions current?

I can't find the appropriate lines or places in index.php.

Also, around line 792, (at the bottom of the section after ''/{SITEMAP_LINK}/'') place this line:

Alex
05-25-2006, 04:43 PM
This refers to version 3.1, we need to update these hacks for release 3.2... Probably all the things are more or less the same, only line numbers in scripts differ.

Frankc2
05-27-2006, 09:55 AM
Thank you

Would appreciate it if you can let me know once done because I tried over and over again but am unable to accomplanish this.

Frankc
06-10-2006, 11:42 AM
Any further developments in this regard please?

Alex
06-12-2006, 10:18 AM
This is the 3.2 version of this mod:

1. category_Main.tpl
Place the {SHOW_SUBCATEGORIES} tag somewhere inside the template, where you want the subcategories to show. Preferably at the top of the file, somewhere around the {CATEGORY_NAME} tag. Example:

<tr>
<td colspan="2"><br />{SHOW_SUBCATEGORIES}</td>
</tr>


2. index.php
Place the call to the function that parses the new tag in template, at line 260:

$show_subcategories_HTML = HTML_show_subcategories($cid);


3. template_scripts/default.php
Right after the line 33, insert the following snippet:

$template_manager->assign($show_subcategories_HTML,'/{SHOW_SUBCATEGORIES}/');


4. HTML_function.php
After line 205 place this function to manage the display of subs:

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;
}

Elton
06-13-2006, 01:46 PM
Is there an example of this working to view online?

boccio
06-14-2006, 03:08 PM
We don't have one. Suppose someone who applied this mod can show live example?

I, Brian
07-30-2006, 08:49 PM
Getting errors with this, too.

Currently:
Parse error: syntax error, unexpected T_FUNCTION in /home/(user)/public_html/ezine/HTML_function.php on line 207

ehsan
09-23-2006, 03:22 AM
getting errors, does it work with 3.25 ?!

after modifying files, only gives me blank page!

ehsan
09-24-2006, 09:26 PM
any solution, please?

boccio
12-06-2006, 01:17 PM
Just upgrade to v3.4, it is supported by default... no need for hack anymore.

sea
02-24-2008, 11:27 PM
How can I do this for 4.x?

mandini76
03-21-2008, 01:20 AM
Can I use this for 4.0???

Thanks!!

Micha
03-21-2008, 10:27 AM
Can I use this for 4.0???

Thanks!!

No this can't be used for v4.

Here is little how to accomplish this in version 4:

http://www.vivvo.net/forums/showpost.php?p=10285&postcount=6