View Single Post
  #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