Gossamer Forum
Home : Products : Links 2.0 : Customization :

sort links by new, then alpha?

Quote Reply
sort links by new, then alpha?
how can i sort links by new, then alphabetically?

Quote Reply
Re: sort links by new, then alpha? In reply to
can somebody please help?

Quote Reply
Re: sort links by new, then alpha? In reply to
Ehhh ... isn't that how Links does it by default?? What is the problem?

Quote Reply
Re: sort links by new, then alpha? In reply to
I think they mean to sort by new, then alphabetically, etc. The way it is now, the script sorts by new, then popular, then alphabetically.

I am still trying to figure this out myself, and have been through over 200 postings with still no idea. 'Will keep looking'.

Michelle

Quote Reply
Re: sort links by new, then alpha? In reply to
OK, I see, forgot about the popular.
Replace sub build_sorthit in db_utils.pl with this
Code:
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
}
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
I think this should do it.

John