Gossamer Forum
Home : Products : Links 2.0 : Customization :

Top Ten list of links by hits on home page

Quote Reply
Top Ten list of links by hits on home page
I am getting several PM's from people asking how I did this on my site. So I will give the code I used below below.

Displays the Top X Links on any template created page.

Step 1
======

Add a sub-routine called sub top_ten in the site_html_templates.pl:

sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites on Home Page by number of hits
# More Mods http://members.lycos.co.uk/stu2o0o/phpBB2/viewforum.php?f=1

open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");

LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[17]; # where 17 represent hits field in links.def
$id{$data[0]} = $data[0]; # where 0 represent ID field in links.def
$name{$data[0]} = $data[1]; # where 1 represent title/name field in links.def
$url{$data[0]} = $data[2]; # where 2 represent URL field in links.def

}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) { # How many do you want to display i,e Top 10

# The line below decides on your field length, change 13 to whatever number you like
# If restriction of field is not required comment the line out by placing a # in front of command

$name{$field} = substr($name{$field}, 0, 13) . ".." if (length($name{$field}) > 13);

# The below command prints out the Top X field, I have included with the Title, the number of hits
$output .= "<tr><td>&nbsp;$count. <a href=\"$build_jump_url?ID=$id{$field}\">$name{$field}</a> $tophits{$field}</td></tr>\n";
}
$count++;
}
return $output;
}

Step 2
======

Then define a global tag called topsites in the %globals hash in the site_html_templates.pl file:

topsites => &top_ten

Step 3
======

Add the following tag in whatever template file you want the top ten to show up in:

<table width="140" border="0" cellspacing="0" cellpadding="0">
<%topsites%>
</table>


# End of Mod
Subject Author Views Date
Thread Top Ten list of links by hits on home page stu2000 13490 Aug 25, 2002, 11:01 AM
Thread Re: [stu2000] Top Ten list of links by hits on home page
Stealth 13321 Aug 25, 2002, 12:45 PM
Thread Re: [Stealth] Top Ten list of links by hits on home page
Paul 13329 Aug 25, 2002, 1:28 PM
Post Re: [Paul] Top Ten list of links by hits on home page
Stealth 13301 Aug 25, 2002, 6:13 PM
Thread Re: [Paul] Top Ten list of links by hits on home page
esm 13284 Aug 25, 2002, 6:27 PM
Thread Re: [esm] Top Ten list of links by hits on home page
Stealth 13276 Aug 25, 2002, 7:05 PM
Thread Re: [Stealth] Top Ten list of links by hits on home page
esm 13299 Aug 25, 2002, 7:12 PM
Thread Re: [esm] Top Ten list of links by hits on home page
stu2000 13279 Aug 25, 2002, 8:15 PM
Post Re: [stu2000] Top Ten list of links by hits on home page
esm 13318 Aug 25, 2002, 10:09 PM
Thread Re: [stu2000] Top Ten list of links by hits on home page
Tomcat 12849 Feb 15, 2003, 1:21 PM
Thread Re: [Tomcat] Top Ten list of links by hits on home page
Hamsterpants 12812 Feb 18, 2003, 5:45 AM
Thread Re: [Hamsterpants] Top Ten list of links by hits on home page
Andy 12849 Feb 18, 2003, 6:48 AM
Thread Re: [Andy] Top Ten list of links by hits on home page
Hamsterpants 12833 Feb 18, 2003, 7:40 AM
Thread Re: [Hamsterpants] Top Ten list of links by hits on home page
Andy 12800 Feb 18, 2003, 7:43 AM
Thread Re: [Andy] Top Ten list of links by hits on home page
Hamsterpants 12813 Feb 18, 2003, 7:47 AM
Thread Re: [Hamsterpants] Top Ten list of links by hits on home page
stu2000 12724 Mar 23, 2003, 5:34 AM
Post Re: [stu2000] Top Ten list of links by hits on home page
stu2000 12680 Mar 23, 2003, 5:36 AM
Thread Re: [stu2000] Top Ten list of links by hits on home page
klashinkov_khan 12597 Apr 12, 2003, 1:19 AM
Post Re: [klashinkov_khan] Top Ten list of links by hits on home page
klashinkov_khan 12579 Apr 12, 2003, 1:48 AM
Post Re: [stu2000] Top Ten list of links by hits on home page
stu2000 12625 Apr 12, 2003, 2:07 AM