X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Displaying categories/subcategories in an unordered list (https://forum.x-cart.com/showthread.php?t=10702)

html_sucks 12-02-2004 06:14 AM

Displaying categories/subcategories in an unordered list
 
Hi,

Not sure whether this mod has been previously posted (i really hope not, as i've wasted most of the day trying to figure this out, and done alot of searching :oops:) i've found lots of similar solutions, but nothing list based which displays the subcategory as well. (Useful if using css based dropdown/list menus, such as http://www.brothercake.com/site/products/menu)

Here's a quick screengrab ... output intentionally left very raw
http://www.mylhost.co.uk/list.gif

oh yeah, i'm using 4.0.8, but should work with 4.x i reckon

Right replace skin1/customer/categories.tpl with ...

Code:

{* $Id: categories.tpl,v 1.23 2004/06/24 09:53:29 max Exp $ *}
{capture name=menu}
<ul> {*** start unordered list***}
{section name=l1_cat_num loop=$allcategories} {*** loop ALL categories ***}
        {if $allcategories[l1_cat_num].parentid eq 0} {*** loop root categories/parentid 0 - level 1***}
                [*]{$allcategories[l1_cat_num].category}
               
                {if $allcategories[l1_cat_num].subcategory_count gt 0} {*** check if root cat has child cats ***}
                        <ul>
                                {section name=l2_cat_num loop=$allcategories} {*** loop through sub cats with matching parent id ***}
                                        {if $allcategories[l2_cat_num].parentid eq $allcategories[l1_cat_num].categoryid}
                                                [*]{$allcategories[l2_cat_num].category}
                       
                                        {if $allcategories[l2_cat_num].subcategory_count gt 0} {*** check if parent has child cats***}
                                                <ul>
                                                        {section name=l3_cat_num loop=$allcategories}
                                                                {if $allcategories[l3_cat_num].parentid eq $allcategories[l2_cat_num].categoryid}
                                                                        [*]{$allcategories[l3_cat_num].category}
                                               
                                                                {if $allcategories[l3_cat_num].subcategory_count gt 0} {*** check if parent has child cats***}
                                                                        <ul>
                                                                                {section name=l4_cat_num loop=$allcategories}
                                                                                        {if $allcategories[l4_cat_num].parentid eq $allcategories[l3_cat_num].categoryid}
                                                                                                [*]{$allcategories[l4_cat_num].category}
       
                                                                {/if}{/section}[/list]                                       
                                {/if}{/if}{/section}[/list]                                       
                {/if}{/if}{/section}[/list]               
        {/if}{/if}{/section}[/list]{/capture}
{ include file="menu.tpl" menu_title=$lng.lbl_categories menu_content=$smarty.capture.menu }


Hopefully this will save someone a bit of time, if i had more time i would probably do something more elegant, (probably recursive) but just thought i'd post before i get the sack for doing sod all today :wink:

adpboss 12-02-2004 09:00 PM

Please post the version # this is for.

Thanks for contributing btw. People are always looking for good category display mods.

html_sucks 12-03-2004 12:49 AM

No worries, I did post the version number above, but I probably could have been clearer.

This was developed using version 4.0.8. I'm assuming it will work on 4.x but haven't had time to test on other installations.

May also be worth trying on 3.5.x - as long as $allcategories is supported and the subcategory_count can be checked, all should be fine.

I'm not sure if smarty supports recursion, (will check later) but this could actually be done using a fraction of the code (and also be of unlimited depth).

Oh yeah, if anyone has any joy on other versions let us know! :)

anandat 12-17-2004 10:53 PM

Thanks...it's cool mod :)

killjack47 01-06-2005 10:10 AM

this is a great mod. i used it and it works. awesome job.

but i'm a little stuck because i reorganized things and now i want to list my products in their categories. i only have about 20 products in 5 categories. so it seems like it should be pretty easy to do that. but i've been trying and i'm totally stuck.

do you guys have any idea how you would add products into this code?

mikegat 02-05-2005 05:51 PM

Excellent mod. Just what I was looking for! Works in 4.0.10. I think this needs to be one of the options available in a default x-cart install: Show subcategories in menu.

If you have a store with only a few categories and subcategories, its a waste of clicks to always have to travel to the main category first.

Thanks!

mpj 02-10-2005 07:23 AM

Hi

Many thanks for posting this mod. Exactly what I needed.


I was trying to implement this on the menu section as well.

So for categories.tpl I added

Code:

{section name=cat_num loop=$subcategories}
{if $subcategories[cat_num].category}{assign var="tmp" value="1"}{/if}

<a href="home.php?cat={ $subcategories[cat_num].categoryid }" class="ProductTitle">
{ $subcategories[cat_num].category|escape }</a> ({$subcategories[cat_num].product_count})



{if $config.Appearance.count_products eq "Y"}
{if $subcategories[cat_num].product_count}

({ $subcategories[cat_num].product_count } Products)

{elseif $subcategories[cat_num].subcategory_count}


({ $subcategories[cat_num].subcategory_count } Subcategories)


{/if}
{/if}
{/section}



This code works fine if your in the subcategory listing. However, when you go into the product details, the menu disappears.

I notice it requires {categoryid} but I think in the product menu, it needs to find the {parentid}.


For the index page, would I be able to write an if then statement to turn this code off ?


Many thanks for a great code!

Judith 10-14-2006 02:32 AM

Re: Displaying categories/subcategories in an unordered list
 
That code was gold - thank you

jasonroy 10-20-2006 08:27 AM

Re: Displaying categories/subcategories in an unordered list
 
didnt work in 4.1.3 for me. just made the vert menu display this

<*><*>
<*><*></list>

taponitrof 12-31-2007 06:14 AM

Re: Displaying categories/subcategories in an unordered list
 
Hi,

I tried to use this code, but my menu code came out like this:

[*] [*] [*] [*] [*] [/list]
Any ideas how to make it work in 4.1.9?

Thanks


All times are GMT -8. The time now is 01:11 PM.

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