X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Display a list of Subcategories from a Specific Category (https://forum.x-cart.com/showthread.php?t=40038)

pairodimes 05-26-2008 12:21 PM

Display a list of Subcategories from a Specific Category
 
I have a really customized categories.tpl

The main reason is because I want to limit what people see on each page as far as category pages are concerned.

I use things like:

{if $cat eq 33 or $current_category.parentid eq 33}
...all my hand crafted links...
{/if}

but I would really like to automate the building of these links -
do you know of a simple way to loop through all Subcategories in a specific Category then display them in a simple list?

ex: loop through all subcategories that exist in category 33 and display:
<li class="subCategoryLink"><a href="home.php?cat=34">Subcategory Name</li>

I tried to follow some other threads but they seem to be way overr the top because they are trying to make this a gloabl category listing template. I really want to keep my specific to each category page.

Any help would be great.

toltion 06-07-2008 04:30 PM

Re: Display a list of Subcategories from a Specific Category
 
I needed this too, so I looked at fly-out menu examples and came up with this -

I like to show third-level categories in fourth level subcategories (i.e. all subcategories that share the same parent category of the current category) -

---------------------
{foreach from=$categories item=c}{* list ROOT categories *}
{if $c.subcats gt 0}
{foreach from=$c.subcats item=c2 name=c2}{* list 2nd level subcategories *}

{if $c2.categoryid eq $current_category.parentid}
{assign var='parent_category' value=$c2.category}{* get the name of the Parent Category *}
{/if}

{if $c2.subcats gt 0}
{foreach from=$c2.subcats item=c3 name=c3}{* list 3rd level subcategories *}
{if $c3.parentid eq $current_category.parentid}
<a href="home.php?cat={$c3.categoryid}">{$c3.category }</a><br />
{/if}
{/foreach}
{/if}
{/foreach}
{/if}
{/foreach}
<a href="home.php?cat={$current_category.parentid}">{ $parent_category}</a><br />{* link to Parent Category at end of list *}
----------------

This creates a basic array of categories that share the same parent category of the current 4th level category. You could, of course, easily modify it to show deeper levels.

Light Speed 06-19-2008 05:42 PM

Re: Display a list of Subcategories from a Specific Category
 
Quote:

Originally Posted by toltion
I needed this too, so I looked at fly-out menu examples and came up with this -

I like to show third-level categories in fourth level subcategories (i.e. all subcategories that share the same parent category of the current category) -

---------------------
{foreach from=$categories item=c}{* list ROOT categories *}
{if $c.subcats gt 0}
{foreach from=$c.subcats item=c2 name=c2}{* list 2nd level subcategories *}

{if $c2.categoryid eq $current_category.parentid}
{assign var='parent_category' value=$c2.category}{* get the name of the Parent Category *}
{/if}

{if $c2.subcats gt 0}
{foreach from=$c2.subcats item=c3 name=c3}{* list 3rd level subcategories *}
{if $c3.parentid eq $current_category.parentid}
<a href="home.php?cat={$c3.categoryid}">{$c3.category }</a><br />
{/if}
{/foreach}
{/if}
{/foreach}
{/if}
{/foreach}
<a href="home.php?cat={$current_category.parentid}">{ $parent_category}</a><br />{* link to Parent Category at end of list *}
----------------

This creates a basic array of categories that share the same parent category of the current 4th level category. You could, of course, easily modify it to show deeper levels.


Could you list the tpl file this code goes in and the before and after code showing how this code is added to that tpl file?

toltion 06-20-2008 01:08 PM

Re: Display a list of Subcategories from a Specific Category
 
I add the code to "/skin1/customer/main/subcategories.tpl" just below -

{if $tmp and $products ne "" }

and above -

<br clear="left" />
<hr size="1" noshade="noshade" />
{/if}

Light Speed 06-20-2008 01:54 PM

Re: Display a list of Subcategories from a Specific Category
 
Quote:

Originally Posted by toltion
I add the code to "/skin1/customer/main/subcategories.tpl" just below -

{if $tmp and $products ne "" }

and above -

<br clear="left" />
<hr size="1" noshade="noshade" />
{/if}


Thanks!

alla 08-24-2008 10:08 AM

Re: Display a list of Subcategories from a Specific Category
 
What is subcats?
Thx

Asiaplay 08-24-2008 09:23 PM

Re: Display a list of Subcategories from a Specific Category
 
"subcats" = "sub-category" type of category
i.e. a "sub-category" is any category which you set up, which is not a "root" level category. See category management wihin X-Cart admin to understand more... the "Root level" is shown for only the top (1st) level of categories you have added (any categories added below the root level ones are called a sub-category)....

Hope comment helps, cheers, Asiaplay

alla 08-25-2008 04:36 PM

Re: Display a list of Subcategories from a Specific Category
 
Quote:

Originally Posted by Asiaplay
"subcats" = "sub-category" type of category
i.e. a "sub-category" is any category which you set up, which is not a "root" level category. See category management wihin X-Cart admin to understand more... the "Root level" is shown for only the top (1st) level of categories you have added (any categories added below the root level ones are called a sub-category)....

Hope comment helps, cheers, Asiaplay



If i display $subcats or use your code I get nothing.
So $subcats does not exist as a variable.

Asiaplay 08-25-2008 05:51 PM

Re: Display a list of Subcategories from a Specific Category
 
Check your own code to see what variable was used in original code (and use logic)... the variables sometimes change depending on version you use (but surprised this one does)... and I have no idea what version you are using (as never heard of default version Alla - perhaps update your signature). This is not my code, I was just trying to explain to you the meaning of $subcats ... :)

Cheers, Asiaplay

alla 08-30-2008 12:37 PM

Re: Display a list of Subcategories from a Specific Category
 
in subcategories.tpl, $subcategories is NULL if the page lists the products from the subcategory

Is there any other variable that will alow me to display the subcategories on this page http://demo.x-cart.com/demo/home.php?cat=23

Thank You


All times are GMT -8. The time now is 12:19 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.