Home : Products : Gossamer Links : Discussions :

Products: Gossamer Links: Discussions: Re: [qango] Category Sort Order (@Related): Edit Log

Here is the list of edits for this post
Re: [qango] Category Sort Order (@Related)
I think I've got this fixed now, so here's the actual mod to reorder subcategories (containing renamed related cats) into the correct alphabetical order.

In build.pm under sub build_category find
# Get the subcategories and related categories as either Yahoo style (integrated) or
# separated into two outputs..
:

Add the following, line after $display{category_loop} = [$category];

Code:
$display{category_sorted_loop} = [$category];


In the 'while' statement a little further down, update it by adding the new line as follows:

Code:
while (my $cat = $sth->fetchrow_hashref) {
if (exists $rel{$cat->{ID}}) {
$cat->{Related} = 1;
$cat->{Name} = $rel{$cat->{ID}};
}
push @{$display{category_loop}}, $cat;
push @{$display{sort_data}}, $cat;
}


After the 'while' statement, add the following:

Code:
# Take the current category_loop array of hashes and reorder by the value of the 'Name' field
foreach my $hashref ( sort {$$a{Name} cmp $$b{Name}} @{$display{sort_data}}) {
push @{$display{category_sorted_loop}}, $hashref;
}


Now update the category display line by adding the new sorted subcategory display, as follows:

Code:
$display{category} = Links::SiteHTML::display ('print_cat', $display{category_loop});
$display{categorysorted} = Links::SiteHTML::display ('print_cat', $display{category_sorted_loop});

This adds a new variable <%categorysorted%> for use in your category template. Simply replace <%category%> with <%categorysorted%> in your template to see the resulting re-sorted subcategory table.

Notes:
  • A cavaet is that you MUST give each related category a name.


  • If you've renamed your 'Name' field in the Category table, you'll need to adjust the code to suit the field name you've used. Adjust it at the sort in the foreach statement where you see $$a{Name} $$b{Name}


  • I've maintained the original <%category%> display variable as a backup, just in case I haven't got this mod quite right. If you need to, you can just reinsert <%category%> to get your old subcategory tables back.


  • AFAIK it works for both static and dynamic builds, although I'm not sure how much of a performance difference there will be on a large number of subcategories.


  • Hope this helps.

    All the best
    Shaun

    Last edited by:

    qango: Aug 12, 2002, 1:00 AM

    Edit Log: