Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Display a list of Subcategories from a Specific Category

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 05-26-2008, 12:21 PM
  pairodimes's Avatar 
pairodimes pairodimes is offline
 

Advanced Member
  
Join Date: Dec 2007
Posts: 50
 

Default 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.
__________________
------
Brian

Portland web design / development
X-Cart 4.1.9 (a few carts)
X-Cart 4.2.0 (1 cart so far)
Reply With Quote
  #2  
Old 06-07-2008, 04:30 PM
 
toltion toltion is offline
 

Advanced Member
  
Join Date: Jun 2007
Posts: 39
 

Default 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.
__________________
X-Cart Gold 4.1.9
Gift Registry/Special Offers
Advanced mini-cart
XC-SEO
Mulltiple Category/Product Templates
Also bought/recently viewed
Feedback reviewer/viewer bundle
Marketing Manager Pro bundle
many more mods
Reply With Quote
  #3  
Old 06-19-2008, 05:42 PM
 
Light Speed Light Speed is offline
 

X-Adept
  
Join Date: Mar 2003
Posts: 921
 

Default 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?
Reply With Quote
  #4  
Old 06-20-2008, 01:08 PM
 
toltion toltion is offline
 

Advanced Member
  
Join Date: Jun 2007
Posts: 39
 

Default 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}
__________________
X-Cart Gold 4.1.9
Gift Registry/Special Offers
Advanced mini-cart
XC-SEO
Mulltiple Category/Product Templates
Also bought/recently viewed
Feedback reviewer/viewer bundle
Marketing Manager Pro bundle
many more mods
Reply With Quote
  #5  
Old 06-20-2008, 01:54 PM
 
Light Speed Light Speed is offline
 

X-Adept
  
Join Date: Mar 2003
Posts: 921
 

Default 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!
Reply With Quote
  #6  
Old 08-24-2008, 10:08 AM
 
alla alla is offline
 

Member
  
Join Date: Aug 2008
Posts: 21
 

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

What is subcats?
Thx
__________________
Gold, X-Cart version 4.1.10
Reply With Quote
  #7  
Old 08-24-2008, 09:23 PM
 
Asiaplay Asiaplay is offline
 

X-Wizard
  
Join Date: Oct 2005
Posts: 1,242
 

Default 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
__________________
X-Cart Gold version 4.1.9
(plus built in X-Cart bugs!)
Reply With Quote
  #8  
Old 08-25-2008, 04:36 PM
 
alla alla is offline
 

Member
  
Join Date: Aug 2008
Posts: 21
 

Default 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.
__________________
Gold, X-Cart version 4.1.10
Reply With Quote
  #9  
Old 08-25-2008, 05:51 PM
 
Asiaplay Asiaplay is offline
 

X-Wizard
  
Join Date: Oct 2005
Posts: 1,242
 

Default 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
__________________
X-Cart Gold version 4.1.9
(plus built in X-Cart bugs!)
Reply With Quote
  #10  
Old 08-30-2008, 12:37 PM
 
alla alla is offline
 

Member
  
Join Date: Aug 2008
Posts: 21
 

Default 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
__________________
Gold, X-Cart version 4.1.10
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

   

 
X-Cart forums © 2001-2020