Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Split level sub categories

Quote Reply
Split level sub categories
Hi,

I'm in the process of upgrading to Glinks 3.1 from LinksSQL 2.1

I have hard-coded a mod into 2.1 to split sub-categories into two levels - upper, then lower. (This allows me to put certain popular sub-cats at the top of the page, over and above the rest of the sub-cats for that category.)

I do this using a field in the Categories table CatLevel (1 or [2]) [2 is default].

Ideally I would like two separate globals <%SubCats1%> and <%SubCats2%> based on the field for each sub-category - any idea on how I would go about starting on this?

Thanks,
Shaun
Quote Reply
Re: [qango] Split level sub categories In reply to
Something like this (just change CatLevel for the other one) - note that this is a modified version of one of my globals so it might be buggy:

sub {
my $tags = shift;
my $id = $tags->{FatherID};
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Name');
my $sth = $cat_db->select ( { FatherID => $id, CatLevel => '1'}, ['ID','Full_Name','Name','Number_Of_Links'] );
my $output;
while (my ($ID,$root_cat,$full_name,$links) = $sth->fetchrow_array) {
my $table = $DB->table('Category');
my $url = $cat_db->as_url($root_cat);
$output .= qq~<li><a href="/shops/$url/"><b>$full_name</b></a> ($links links)</li>~;
}
return $output;
}
Quote Reply
Re: [afinlr] Split level sub categories In reply to
afinlr,

Thanks for the reply - it didn't quite work out - I'll have a better look at it when I get more time.

However, I've posted my orignal 2.1.0 code modification into another related thread and wondered if you wouldn't mind having a look and giving some advice

http://www.gossamer-threads.com/...i?post=292806#292806

Thanks,
Shaun
Quote Reply
Re: [qango] Split level sub categories In reply to
Can you explain how 'it didn't quite work out' - did you get an error message or did it just not give you what you wanted? I think that each of your three globals can be similar to this if we can get it to work.
Quote Reply
Re: [afinlr] Split level sub categories In reply to
No errors, just not really the results in they way that I wanted.

Firstly I had to change [my $id = $tags->{FatherID};] to [my $id = $tags->{ID};] to get the correct sub-cats, but it only displays them in a single column, and it doesn't take account of any Yahoo style related subcats.

I agree, it would be great if we could get it working Smile
Quote Reply
Re: [qango] Split level sub categories In reply to
Can you try this:

Code:

sub {
my $tags = shift;
my $id = $tags->{ID};
my $cat_db = $DB->table('Category');
my $related_db = $DB->table('CatRelations');
my $output;
my $sth = $cat_db->select ( { FatherID => $id}, ['ID'] );
$sth->rows() and (my $subcat_ids = $sth->fetchall_arrayref);
$sth = $related_db->select ( { CategoryID => $tags->{ID} }, ['RelatedID','RelationName'] ) or die $GT::SQL::error;
$sth->rows() and (my $relate_ids = $sth->fetchall_arrayref);
if (@$subcat_ids || @$relate_ids) {
my %rel = map { $_->[0] => $_->[1] } @$relate_ids;
my $ids = '(' . join (",", map { $_->[0] } @$subcat_ids, @$relate_ids) . ')';
$cat_db->select_options ("ORDER BY $CFG->{build_category_sort}") if ($CFG->{build_category_sort});
$sth = $cat_db->select ( GT::SQL::Condition->new ('ID', 'IN', \$ids) );
while (my $cat = $sth->fetchrow_hashref) {
if (exists $rel{$cat->{ID}}) {
$cat->{Related} = 1;
$cat->{Name} = $rel{$cat->{ID}};
}
if ($cat->{Cat_Level} eq "1") {
push @{$output->{category_loop_top}}, $cat;
}
else {
if ($cat->{AlphaBar} eq "Yes") {
push @{$output->{category_alpha_loop}}, $cat;
}
else {
push @{$output->{category_loop}}, $cat;
push @{$output->{sort_data}}, $cat;
}
}
}
if (exists $output->{sort_data}) {
foreach my $hashref ( sort {lc($a->{Name}) cmp lc($b->{Name})} @{$output->{sort_data}}) {
push @{$output->{category_sorted_loop}}, $hashref;
}
}
$output->{categoryalpha} = Links::SiteHTML::display ('print_cat_alpha', $output->{category_alpha_loop});
$output->{categorytop} = Links::SiteHTML::display ('print_cat_top', $output->{category_loop_top});
$output->{category} = Links::SiteHTML::display ('print_cat', $output->{category_loop});
if (exists $output->{category_sorted_loop}) {
$output->{categorysorted} = Links::SiteHTML::display ('print_cat', $output->{category_sorted_loop});
}}
return {CatSorted=>$output};
}


If you do <%DUMP CatSorted%> you should be able to see whether it works or not.