Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Sorting Categories... Can It Be Done?

Quote Reply
Sorting Categories... Can It Be Done?
Is there a way to create a fields in my catgeories table such as "Priority" and then sort on this basis? For instance, I am currently sortking alphabetical, but there are a few cases where I would like to sort in order of "importance."

Any insight here? Thanks.

Quote Reply
Re: Sorting Categories... Can It Be Done? In reply to
Hi!

There's no built in way, but you can easily add a Priority field to category. Then to change the sort order, it's in HTML_Templates.pm, sub site_html_print_cat:


foreach $cat (sort @names) {

the sort defaults to alphabetically. To sort by priority it should look something like:

foreach $cat (sort { $subcat->{$a}->{Priority} <=> $subcat->{$b}->{Priority} } @names) {

Hope that helps!

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Sorting Categories... Can It Be Done? In reply to
Hi Alex,

Thanks for the tip. I made the change, setting 0 as the default for Priority in the Category table. However, except for where and when I set a value for the Priority field, the sorting does not make sense.

In other words, take a look at:

http://www.hothockey.com

I have not set a priority on any of these main categories, instead hoping to sort them alphabetically, but as you can see, I cannot tell how things are sorted! :)

However, if you go to:

http://www.hothockey.com/pages/Teams/International/Germany/

You will see the Priority sort worked. I set priorities of 100, 200, 300, 400, and 5000 respectively on the Elite League, Second Div, Third North, Third South, and Fourth.

In the end, these are the only categeories with priorities set, and the sort works fine. However, where the priorities are 0 (as they are everywhere else) I would like the sort to be alphabetical.

Do you see what I am saying, and do you (or anyone else) know how I can fix this?

Thanks!

Quote Reply
Re: Sorting Categories... Can It Be Done? In reply to
Change:

foreach $cat (sort { $subcat->{$a}->{Priority} <=> $subcat->{$b}->{Priority} } @names) {

to:

foreach $cat (sort {
($subcat->{$a}->{Priority} <=> $subcat->{$b}->{Priority}) or
(lc $subcat->{$a}->{Name} cmp lc $subcat->{$b}->{Name})
} @names) {

and that should sort by priority first, and then alphabetically.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Sorting Categories... Can It Be Done? In reply to
Alex,

When I do this, I get "(Unkown Tag: Number_of_Links)" showing up on my index page, for each place where the hyperlinked category should exist. And now, even when I put it back to the original "foreach $cat (sort { $subcat->{$a}->{Priority} <=> $subcat->{$b}->{Priority} } @names) {" I am getting the same thing.

Links are building properly, but my categories and subcategories all show up with "(Unkown Tag: Number_of_Links)"

How do I fix this?

Thanks again!