Okay, here's the code.
It actually creates three separate category groups:- AlphaBar, Top Level, and then the usual regular (level 2) categories.
There are two custom fields in the Category table to achieve this (
AlphaBar [Yes,No]) and (
Cat_Level [1,2])
Ideally I'd like this same functionality using globals in Glinks, without having to manually edit Build.pm
On the category page itself, I would like the have <%AlphaBar%> if needed (check all subcats for AlphaBar eq 'Yes'), then the level 1 subcats <%SubCats1%>, then the remaining level 2 afterwards <%SubCats2%>.
Any help or advice greatly appreciated
Quote:
# Get the subcategories and related categories as either Yahoo style (integrated) or
# separated into two outputs..
my $subcat_ids = []; my $relate_ids = [];
$display{category_loop} = [$category];
$display{category_loop_top} = [$category];
$display{category_alpha_loop} = [$category];
$display{category_sorted_loop} = [$category];
if ($CFG->{build_category_yahoo}) {
$sth = $cat_db->select ( { FatherID => $category->{ID} }, ['ID'] );
$sth->rows() and ($subcat_ids = $sth->fetchall_arrayref);
$sth = $related_db->select ( { CategoryID => $category->{ID} }, ['RelatedID','RelationName'] ) or die $GT::SQL::error;
$sth->rows() and ($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 @{$display{category_loop_top}}, $cat;
}
else {
if ($cat->{AlphaBar} eq "Yes") {
push @{$display{category_alpha_loop}}, $cat;
}
else {
push @{$display{category_loop}}, $cat;
push @{$display{sort_data}}, $cat;
}
}
}
# Take the current category_loop array of hashes and reorder by the value of the 'Name' field
if (exists $display{sort_data}) {
foreach my $hashref ( sort {lc($a->{Name}) cmp lc($b->{Name})} @{$display{sort_data}}) {
push @{$display{category_sorted_loop}}, $hashref;
}
}
# Print out the sub-category tables
$display{categoryalpha} = Links::SiteHTML::display ('print_cat_alpha', $display{category_alpha_loop});
$display{categorytop} = Links::SiteHTML::display ('print_cat_top', $display{category_loop_top});
$display{category} = Links::SiteHTML::display ('print_cat', $display{category_loop});
if (exists $display{category_sorted_loop}) {
$display{categorysorted} = Links::SiteHTML::display ('print_cat', $display{category_sorted_loop});
}
}
else {
$display{categoryalpha} = '';
$display{categorytop} = '';
$display{category} = '';
$display{categorysorted} = '';
shift @{$display{category_alpha_loop}};
shift @{$display{category_loop_top}};
shift @{$display{category_loop}}; # The loop var shouldn't have the root cat.
shift @{$display{category_sorted_loop}};
}
}