![]() |
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. |
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. |
Re: Display a list of Subcategories from a Specific Category
Quote:
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? |
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} |
Re: Display a list of Subcategories from a Specific Category
Quote:
Thanks! |
Re: Display a list of Subcategories from a Specific Category
What is subcats?
Thx |
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 |
Re: Display a list of Subcategories from a Specific Category
Quote:
If i display $subcats or use your code I get nothing. So $subcats does not exist as a variable. |
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 |
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.