Gossamer Forum
Home : Products : Links 2.0 : Customization :

Random links with Priority always first

Quote Reply
Random links with Priority always first
I have spent two days reading the forums because I know that the answers are here, it's just putting them all together for what I want that is the problem.

I would like to have the links rotate randomly with each build but yet keep links that have been labeled "Priority" at the top of the list.

Here is what I've done so far:

db_utils.pl - sub build_sorthit

my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %priority, %isnew, %iscool, $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);
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
}
foreach $hit (sort {
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});

return (rand > 0.5) ? 1 : -1;
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}

And I also changed this

my (%sortby, %priority, %isnew, %iscool, $hit, $i, @sorted);

Then I added the following in links.def

Priority => [14, 'alpha', 0, 5, 0, 'No', '']

$db_priority = 14;

The first problem I have is that when I go to the admin and try to add a link there's a field for Priority, but it's only a box with with "No" in it. What am I missing?

I haven't added any links yet because I'm concerned that I don't have this right because the Priority Field doesn't have the drop down menu with the options like the "isNew" or "isPopular" Fields.

I've worked with Links2 for awhile and have done a few modifications, but this one really has me stumped.

One other question - will the "Priority" links have that next to them like "New" and "Pop" or will it just be a field that can be for admin?

Thank you to anyone who can offer some help. I really have tried to go through the past posts and cobble this together.
Subject Author Views Date
Thread Random links with Priority always first SandraJ 4364 Jul 15, 2003, 7:37 PM
Post Re: [SandraJ] Random links with Priority always first
esm 4310 Jul 15, 2003, 9:02 PM
Thread Re: [SandraJ] Random links with Priority always first
esm 4309 Jul 15, 2003, 9:06 PM
Thread Re: [esm] Random links with Priority always first
SandraJ 4284 Jul 17, 2003, 8:00 PM
Thread Re: [SandraJ] Random links with Priority always first
SandraJ 4280 Jul 17, 2003, 9:18 PM
Thread Re: [SandraJ] Random links with Priority always first
esm 4285 Jul 17, 2003, 9:42 PM
Thread Re: [esm] Random links with Priority always first
SandraJ 4276 Jul 18, 2003, 10:18 AM
Post Re: [SandraJ] Random links with Priority always first
SandraJ 4227 Jul 30, 2003, 1:00 PM