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

Displaying categories/subcategories in an unordered list

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 12-02-2004, 06:14 AM
 
html_sucks html_sucks is offline
 

Advanced Member
  
Join Date: May 2004
Location: London, UK
Posts: 63
 

Default 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 ) 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
Reply With Quote
  #2  
Old 12-02-2004, 09:00 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Please post the version # this is for.

Thanks for contributing btw. People are always looking for good category display mods.
Reply With Quote
  #3  
Old 12-03-2004, 12:49 AM
 
html_sucks html_sucks is offline
 

Advanced Member
  
Join Date: May 2004
Location: London, UK
Posts: 63
 

Default

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!
Reply With Quote
  #4  
Old 12-17-2004, 10:53 PM
 
anandat anandat is offline
 

X-Adept
  
Join Date: Jan 2004
Posts: 914
 

Default

Thanks...it's cool mod
__________________
X-Cart: 4.7.7 LIVE
Skin:Ultra by xcartmods.co.uk
X-cart Modules: | ACR, Rich Google Search, Customer Testimonials | Cloud Search, | Websitecm: CDSEO (2.1.9)
---------------
Server: Linux
php: 5.3
mysql: 5.0.89
----------------
Reply With Quote
  #5  
Old 01-06-2005, 10:10 AM
 
killjack47 killjack47 is offline
 

Newbie
  
Join Date: Dec 2004
Posts: 3
 

Default

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?
Reply With Quote
  #6  
Old 02-05-2005, 05:51 PM
 
mikegat mikegat is offline
 

Newbie
  
Join Date: Apr 2004
Posts: 3
 

Default

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!
Reply With Quote
  #7  
Old 02-10-2005, 07:23 AM
 
mpj mpj is offline
 

Senior Member
  
Join Date: Feb 2005
Posts: 106
 

Default

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!
__________________
X-Cart 4.0.11


{My simple mods}
Adding Market list and % save on product detail
Quantity input box
Reply With Quote
  #8  
Old 10-14-2006, 02:32 AM
 
Judith Judith is offline
 

Member
  
Join Date: Oct 2006
Posts: 23
 

Default Re: Displaying categories/subcategories in an unordered list

That code was gold - thank you
__________________
X-Cart Version 4.1.8
Reply With Quote
  #9  
Old 10-20-2006, 08:27 AM
  jasonroy's Avatar 
jasonroy jasonroy is offline
 

Senior Member
  
Join Date: Sep 2006
Location: Tualatin, Oregon
Posts: 147
 

Default Re: Displaying categories/subcategories in an unordered list

didnt work in 4.1.3 for me. just made the vert menu display this

<*><*>
<*><*></list>
__________________
rjroffroad.com
x-cart 4.1.3
+ez checkout
+remember anonymous carts
Reply With Quote
  #10  
Old 12-31-2007, 06:14 AM
 
taponitrof taponitrof is offline
 

Senior Member
  
Join Date: Dec 2007
Posts: 105
 

Default 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
__________________
X-Cart Version 4.1.10, 4.1.11, 4.2, 4.3, 4.4.5
Linux
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 08:04 PM.

   

 
X-Cart forums © 2001-2020