imstillatwork
IS-IT--Management
I'm having a heck of a time figuring out how to collaps and expand this category tree correctly based on the url variable 'path'
Any ideas would be awsome. It looks so simple at first. maybe I am trying too hard?
I'm aiming for unlimited category levels for a store catalog I'm working on to replace my old standard code of 2 levels only that I built several years ago.
In action:
I've tried several things to get it to collapse and expand properly, but left it unmolested for you guys to play with. Please!!
Code:
Basicly all of the childeren of any expanded or current levels need to be visable also.
For example see
Any ideas would be awsome. It looks so simple at first. maybe I am trying too hard?
I'm aiming for unlimited category levels for a store catalog I'm working on to replace my old standard code of 2 levels only that I built several years ago.
In action:
I've tried several things to get it to collapse and expand properly, but left it unmolested for you guys to play with. Please!!
Code:
Code:
<!--- default values for vars --->
<cfparam name="attributes.parentid" default="0">
<cfparam name="attributes.path" default="0">
<!--- query to get categories --->
<cfquery datasource="#application.dsn#" name="qgetcats">
SELECT * FROM cart_categories
WHERE categories_parent_id = #attributes.parentid#
ORDER BY categories_name ASC
</cfquery>
<!--- output query --->
<cfoutput query="qgetcats">
<!--- set path for url --->
<cfif attributes.path EQ 0>
<!--- if no path is set, make one with the current categories_id --->
<cfset path=categories_id>
<cfelse>
<!--- if path is set, add to it with the current categories_id --->
<cfset path=listappend(attributes.path,categories_id,"_")>
</cfif>
<!--- indentation level --->
<cfset padding=listlen(path,"_")*10>
<!--- bold if current pick --->
<cfif url.path EQ path>
<cfset weight="bold">
<cfelse>
<cfset weight="normal">
</cfif>
<!--- display category in div --->
<div style="padding-left:#padding#px;font-weight:#weight#;">
<a href="index.cfm?path=#path#">#categories_name#</a>
</div>
<!--- rinse, repeat --->
<cf_cats parentid="#categories_id#" path="#path#">
</cfoutput>
Basicly all of the childeren of any expanded or current levels need to be visable also.
For example see