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

ALWAYS display first level subcats beneath root cats

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 04-11-2005, 04:50 AM
 
ExoZed ExoZed is offline
 

Member
  
Join Date: Apr 2005
Posts: 28
 

Default ALWAYS display first level subcats beneath root cats

I've experimented with a couple of mods on here for this, which are really great mods, but people keep asking how to get the first level subcategories displayed beneath EVERY root category ALL the time like this:

Root category 1
- subcategory 1a
- subcategory 1b
- subcategory 1c

Root category 2
- subcategory 2a
- subcategory 2b
- subcategory 2c

Root category 3
- subcategory 3a
- subcategory 3b
- subcategory 3c

So I adapted Fernandos mod to do it - it actually only required trimming it down and just adding an if statement to check each subcategory against the current root category id it's looping through.

Below is my whole skin1/categories.tpl file which is the only thing that needs modding:

Code:
{* $Id: categories.tpl,v 1.23 2004/06/24 09:53:29 max Exp $ *} {capture name=menu} {if $active_modules.Fancy_Categories ne ""} {include file="`$fancycategories_config.modules_path`/fancy_categories.tpl"} {else} {if $config.General.root_categories eq "Y"} {section name=cat_num loop=$categories} <FONT class="CategoriesList">{$categories[cat_num].category}</FONT> {section name=subcat loop=$allcategories} {if $allcategories[subcat].parentid eq $categories[cat_num].categoryid} {$allcategories[subcat].category} {/if} {/section} {/section} {else} {section name=cat_num loop=$subcategories} <FONT class="CategoriesList">{$subcategories[cat_num].category}</FONT> {/section} {/if} {/if} {/capture} { include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_categories menu_content=$smarty.capture.menu }

The above is just a mod on the original x-cart template so there's no other stuff in there to confuse the issue.
__________________
--------------------------------------------


4.0.14-gold_upgrade
Reply With Quote

The following user thanks ExoZed for this useful post:
donavichi (10-25-2009)
  #2  
Old 05-19-2005, 11:02 PM
 
IndieDepot IndieDepot is offline
 

Advanced Member
  
Join Date: May 2005
Posts: 30
 

Default

Good Job! Thanks for this mod!

- Shannon
__________________
- www.TheShotList.com
X-Cart version 4.0.13
PHP 4.3.10
MySQL 4.0.23
Web server Apache
Operation system Linux
Perl 5.008004
XML parser (expat) 1.95.6
Reply With Quote
  #3  
Old 05-23-2005, 10:30 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default

Nice first post! Many thanks.
__________________
xcartmods.co.uk
Reply With Quote
  #4  
Old 05-23-2005, 11:49 PM
 
ExoZed ExoZed is offline
 

Member
  
Join Date: Apr 2005
Posts: 28
 

Default menu mod

glad it helped

I think you can use Fancy Categories for this sort of thing, but considering how easy it is to do, it's worth just modding it.

Also, while you're looping through the subcategories you can use their other values to do things like changing link locations or text styles etc - I used the categories position value to determine different hrefs.
__________________
--------------------------------------------


4.0.14-gold_upgrade
Reply With Quote
  #5  
Old 05-23-2005, 11:56 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

Great mod, keep in mind it loops through ALL of your categories many times over, so if you have a lot of categories this is going to be a LOT of overhead to your page loading. If that's the case for you, your better to run the mod, copy the html, and hard code them.
Reply With Quote
  #6  
Old 05-24-2005, 12:17 AM
 
ExoZed ExoZed is offline
 

Member
  
Join Date: Apr 2005
Posts: 28
 

Default loading

I have considered that yes, as I do have quite a few categegories, but saying that, am very happy with the speed of it.

But (and without actually figuring it out) you could probably break up the subcategories array or just loop through the relevant parts... anyone facy doing that...?
__________________
--------------------------------------------


4.0.14-gold_upgrade
Reply With Quote
  #7  
Old 05-24-2005, 11:25 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

No other way to do it via smarty alone, subcategories array only holds the subcategories of the current category.
Reply With Quote
  #8  
Old 05-24-2005, 12:56 PM
 
1320AutoSports 1320AutoSports is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 89
 

Default

Quote:
Originally Posted by Jon
Great mod, keep in mind it loops through ALL of your categories many times over, so if you have a lot of categories this is going to be a LOT of overhead to your page loading. If that's the case for you, your better to run the mod, copy the html, and hard code them.

Tell me about it..

I have about 50+ categories w/ 3 - 6 categories each.. ..

I am going to do mine all static....
Reply With Quote
  #9  
Old 07-02-2005, 05:46 PM
 
orionblu orionblu is offline
 

Newbie
  
Join Date: Jun 2005
Posts: 9
 

Default

This mod is very helpful - however I am having trouble with one thing. I have a few root categories, some with sub and then sub-sub categories, others with no subs. I would like the root/sub/sub-sub categories from only one root at a time to appear on its respective page. For example:

Materials (root)
Siding (sub)
vinyl (sub sub)
aluminum (sub sub)
tiles (sub)
shingles (sub)

This appears on the materials.php page of the website. Another menu will appear on the services.php page.

I am x-cart version 4 0 14.

I would really appreciate any help with this, I'm super pleased with x-cart Gold so far and don't want to get stumped so as to not continue using it.

Thanks for any suggestions!
__________________
Version 4.0.14
Reply With Quote
  #10  
Old 07-03-2005, 10:58 PM
 
bluski bluski is offline
 

Newbie
  
Join Date: May 2005
Posts: 4
 

Default

Thanks for the mod. Just what I was seeking, and there were only old posts for older versions. So thanks, ExoZed!!!

I modified your code so that all main categories will show on home page and when you click on a main category, only the subcats for that cat will show (and stay shown!) while the main categories will always show.

I'm new to PHP and Smarty, so someone please check my code.


Code:
{* $Id: categories.tpl,v 1.23 2004/06/24 09:53:29 max Exp $ *} {capture name=menu} {if $active_modules.Fancy_Categories ne ""} {include file="`$fancycategories_config.modules_path`/fancy_categories.tpl"} {else} {if $config.General.root_categories eq "Y"} {section name=cat_num loop=$categories} <FONT class="CategoriesList">{$categories[cat_num].category}</FONT> {if $cat eq $categories[cat_num].categoryid || $current_category.parentid eq $categories[cat_num].categoryid} {section name=subcat loop=$allcategories} {if $allcategories[subcat].parentid eq $categories[cat_num].categoryid} {$allcategories[subcat].category} {/if} {/section} {/if} {/section} {else} {section name=cat_num loop=$subcategories} <FONT class="CategoriesList">{$subcategories[cat_num].category}</FONT> {/section} {/if} {/if} {/capture} { include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_content=$smarty.capture.menu }
__________________
4.1.5 Gold
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 11:32 PM.

   

 
X-Cart forums © 2001-2020