Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Category & Subcategory lists

Quote Reply
Category & Subcategory lists
Alex,

I'm trying to port the side-bar mod over, and enhance it with a feature to expand the local sub-categories (now that we can find them).

Is there a way to make a simple call to get a list of the top level categories, then the subcategories at the current level?

I'm trying for something like:

Code:
Top_Level_1
Top_Level_2
Second_Level_1
Second_Level_2
Third_Level_1
Third_Level_2
Third_Level_3
Third_Level_4
Third_Level_5
Third_Level_6
Third_Level_7
Third_Level_8
Second_Level_3
Top_Level_3
Top_Level_4
I figure if you know what level you are at, you can backtrack and get the path up to the top (or parse out the Full Name from the category table).

I would expect the _max_ depth in this 0-based field would be 3 (4 levels)
and there would only be up to 20 categories at any level. I'm not trying to make a solution to handle DMOZ <G>

Also, because this is something that would not change very often, it could be written out to a series of files that can be <%include category_sidebar_level%> since even 20x20 is only 400. The speed benefit far outweighs the diskspace.

This would make a perfect plug-in, with a single admin option to re-generate the level files, and perhaps some user options to customize the display (as well as the ability to edit the template via the regular editor).

I really need this, so one way or another I've got to fgiure it out, and it would make a cool little plug-in.

The subroutines to grab_top_level_categories, grab_current_level_categories, and grab_path_from_top would be great widgets in their own right, but something like that already exists... I just can't figure out how to call it.

Also, there are ways to make this dynamic, using partial templates, and partial look-ups, that could cut out the 'leaf' files, by pre-generating the various category template files, and then only selecting out and high-lighting the "leaf" category you are currently in. These fall under pwerformance tweaks, but I need a pointer on the best way to grab the categories at a given level.




PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Category & Subcategory lists In reply to
Hi!

First, you need a category table object:

my $table = $DB->table('Category');

Then, to get root level categories:

my $sth = $table->select( { FatherID => 0 }, ['ID', 'Full_Name'] );

This will only get the ID and Full_Name fields, you should avoid SELECT *'s when you don't need them.

To get a list of immediate children of a category:

my $sth = $table->select ( { FatherID => ID_NUMBER }, ['ID','Full_Name'] );

To get a list of all upline parents in order:

my $parents = $table->parents ( ID_NUM );

This returns an array_ref of category ID's.

To get a list of all children of a category:

my $children = $table->children ( ID_NUM );

This returns an array_ref of all children.

This should give you a start, let me know if you get stuck anywhere.

Cheers,

Alex
To get root level categories:



--
Gossamer Threads Inc.
Quote Reply
Re: [pugdog] Category & Subcategory lists In reply to
PupDog,

Did you ever get this to work?


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Category & Subcategory lists In reply to
This isn't quite the same thing but might be a start - a list of the categories:

http://www.gossamer-threads.com/...i?post=243460#243460
Quote Reply
Re: [afinlr] Category & Subcategory lists In reply to
Thanks afinlr,

not what I was looking for - but I can use it elsewhere!


Sandra Roussel
Chonsa Group Design - Fresh Start Housing