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> $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
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> $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