Gossamer Forum
Home : Products : Links 2.0 : Customization :

Random order of links

Quote Reply
Random order of links
I have read the archives on this subject and it was pretty confusing on how to do this and make it work. So I figured I would update the thread. I would like the links to be listed randomly rather then alphabetically (keeping the new and popular links first) within each category. Any info on how to do this would be appreciated (keeping in mind my limited capabilities). Keith
Quote Reply
Re: Random order of links In reply to
Step 1:
=======
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;

---------------------------------------------

Step 2:
=======
Change build_sorthit subroutine in [db.cgi] script to:

sub build_sorthit {

my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_hits + ($i * ($#db_cols+1))];
}
foreach $hit (sort { return $sortby{$b} <=> $sortby{$a} } (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}

---------------------------------------------

That should do it.

Dan Smile
Quote Reply
Re: Random order of links In reply to
Dan: Thanks works like a charm. The only quirk is that I would like to have the NEW links at the top of the list with the popular ones. With your mod it mixes the NEW ones in. is there an easy fix??? Thanks again for your help, it is appreciated.
Quote Reply
Re: Random order of links In reply to
Whoops, one other quick question.... is it possible to put the links in a new random order after each build or will they always stay the same (I rebuilt the links three times but they stayed in the same order)?
Quote Reply
Re: Random order of links In reply to
Hi:

I may have misunderstood you. Are you looking for a random or non-random sorting - or a combination thereof?

It seems you want new sites first followed by the remaining sites in order of popularity. Is this right? If so then this is not random. Further, then unless new sites are added and/or relative popularity of sites changes, the order will remain the same when the database is re-indexed (i.e., updated).

If the case then to place new sites first followed by a numerical sort (on the hits field) of non-new sites is a bit involved. It may require two juxtaposed sorts - the first sorts on time in the database and the other sorts numerically using the code I supplied but excluding new sites (and appends the original sorted array). Perhaps Alex can shed some light.

Dan Smile
Quote Reply
Re: Random order of links In reply to
Hi Dan:

That's the confusion!!!

Ideally I would like the NEW links, followed by the POP links, followed by the rest of the links in random order.

Thanks,
KEITH
Quote Reply
Re: Random order of links In reply to
Alternatively, I would be happy with a total random sort if the above is to complex. Thanks!
Quote Reply
Re: Random order of links In reply to
Whoa, I did find this from Alex in June:

Here's a new mod that will make the popular and new links displayed before any others.

In db.pl, replace build_sorthit with:
<PRE>
sub build_sorthit {
# --------------------------------------------------------
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %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_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($ispop{$i} = 1);
}

foreach $hit (sort {
if ($ispop{$b} and !$ispop{$a}) { return 1; }
if ($ispop{$a} and !$ispop{$b}) { return -1; }
if ($isnew{$b} and !$isnew{$a}) { return 1; }
if ($isnew{$a} and !$isnew{$b}) { return -1; }
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;
}
</PRE>



However, I can't get it to work. If I include the <PRE> tags (what are those for) the program bombs out. Without them the pages are built but they are not randomized with each build.

Keith
Quote Reply
Re: Random order of links In reply to
I have been wrestling with the same thing and to follow is what I have finnaly gotten.
I wanted to list my new links first followed by popular links followed by a random listing of links.

Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;


in the db.pl
sub build_sorthit {
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];

if ($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") { $isnew{$i} = 1; }

if ($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") { $iscool{$i} = 1; }
}
foreach $hit (sort {

if ($isnew{$b} and !$isnew{$a}) { return 1; }

if ($isnew{$a} and !$isnew{$b}) { return -1; }

if ($iscool{$b} and !$iscool{$a}) { return 1; }

if ($iscool{$a} and !$iscool{$b}) { return -1; }

if ($isnew{$a} and $isnew{$b}) { return lc($sortby{$a}) cmp lc($sortby{$b}); }

if ($iscool{$a} and $iscool{$b}) { 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;
}

__________________________________

There may be a better way but this is what I have figured out.

------------------
Thanks for all the help.
Quote Reply
Re: Random order of links In reply to
Hello,

Is there a way to just randomize the order in which the links are displayed in each category each time the directory is rebuilt?

I've had webmasters complain to me that their site never gets visted because they are on like, page more6.html -- they are good sites, but nobody GOES that far when they search.

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Quote Reply
Re: Random order of links In reply to
you can assign tempoary random numbers for each and then sort them Wink

jerry
Quote Reply
Re: Random order of links In reply to
(duplicate post deleted)


[This message has been edited by Sanguinarius (edited September 05, 1999).]
Quote Reply
Re: Random order of links In reply to
 
Quote:
you can assign tempoary random numbers for each and then sort them

What?? How? Remember, I'm not a cgi-genius like you guys are...this is getting really frustrating for me. Frown
Quote Reply
Re: Random order of links In reply to
 
Quote:
I have been wrestling with the same thing and to follow is what I have finnaly gotten.
I wanted to list my new links first followed by popular links followed by a random listing of links.
Change variable $db_sort_links in [links.def] file to equal 8 - $db_sort_links = 8;

That will sort the links by HITS won't it, not random order? Someone, I'm confused here. :/

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Quote Reply
Re: Random order of links In reply to
If there is a mod that will post the links by the following order: new, popular, random order (changing order every time pages are rebuilt), shouldn't it get posted in the Resource center? Smile

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Quote Reply
Re: Random order of links In reply to
Still no help? Well, guess what? I'm still wanting to do this. Can anyone tell me once and for all, definitively, what to do in order to:

put new first followed by pop followed by random links (in a different random order each time I rebuild the page)?

*waves money around* I'm getting desperate...

Please, I don't know if the above mod in the post above is a random sorting with each build.

------------------

--Sanguinarius
The Real Vampire Directory
www.sanguinarius.org/cgi-bin/links/pages/
Quote Reply
Re: Random order of links In reply to
Sanguinarious, did you figure this out?