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
Quote Reply
Re: [stu2000] Top Ten list of links by hits on home page In reply to
How you did it? Don't mean, how you applied a mod that was written by other users, namely Widgetz and me? Wink
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Stealth: Aug 25, 2002, 12:46 PM
Quote Reply
Re: [Stealth] Top Ten list of links by hits on home page In reply to
Quote:
How you did it?

Don't mean, how you applied a mod that was written by other users, namely Widgetz and me?

It was still him that applied it whether it was written by you or not.

He's not going to say "here's how eliot did it on my site"

Tongue
Quote Reply
Re: [Paul] Top Ten list of links by hits on home page In reply to
Well, I think that the way in which the post was written, he was taking credit for applying and "writing" the mod, which is unethical, IMO. Sounded like he did the mod and was posting the codes for it.

Again, Paul, you say "potato", I say "potatoe"...

Tongue
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Paul] Top Ten list of links by hits on home page In reply to
both you guys are somewhat right on this. Stu2000 doesn't apprear to be taking credit for writing the code but could have done a better job of indicating that fact. However, if you look closely there is a line that reads: # More Mods http://members.lycos.co.uk/stu2o0o/phpBB2/viewforum.php?f=1 . This could lead one to believe that stu2000 is the author of the code. I think he should give credit to the author if and when he finds out who wrote it. Otherwise, since he is putting it out there for the public to view I would include a disclaimer that I did not write it and at least point the viewer to G-T forums as the probable source of the code. That seems reasonable. If I dod not write the code, I would avoid even the appearance of being the author.


For those of us who do not write perl code, we need to remember to clearly indicate the source of the code when we present it to others. If we don't know where it comes from, then so state. I guess this would apply to all of us. Just remember to give credit where credit is due and all should be fine.

My thanks to both of you for all you do!


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."

Last edited by:

esm: Aug 25, 2002, 6:38 PM
Quote Reply
Re: [esm] Top Ten list of links by hits on home page In reply to
Yep...every single mod listed in that web page is written by others. He really needs to give credit to the appropriate authors and also make sure he has gotten permission to reprint the codes from the mod authors.

What he has done is unethical and disrespectful, IMO.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Top Ten list of links by hits on home page In reply to
I'm sure he'll take care of it. In a couple of the mods, he did refer the viewer to the appicable threads on the GT forums.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Top Ten list of links by hits on home page In reply to
I agreen to everyones post here in truth. The mod above as you all are aware was orignally posted by Stealth located here http://www.gossamer-threads.com/...tring=length;#188597.

The code above is what I am using on my site, which I have received about 6 pm's asking how I did it. I sent them to that url above, thinking that would be the end of it, but the pm's came back asking how do I add total hits and length descriptions etc. So to that end I posted the codes again.

The forum url stated in the above post admittedly was a mistake. I use the forums for my own use, hence only admins/moderators can post or reply no one else. The code above was a private message just copied and pasted on here. I sent a links user there again because i was being asked what mods are being used on my site. Instead if naming them all I have them posted. Well I thought the forum was personnel and unvisited. Its not linked to from any of my sites, I have never mentioned before in any threads etc etc.

The threads on the forum, have links on the them, so that I know where I got it from in the likelyhood that I may need to change any coding.

If it conitinues to be a problem, I shall either remove it, or make them a private thread where a password is required.

For some reason I cannot edit the above post but if I could or any mod /staff out there, this thread can either be closed, deleted or editted in anyway.

I don't come to these forums for glory or to brag far from it, I come here to learn and experience new ideas for links 2.0 etc etc.

Mods / Staff please edit this thread as required, not that you need my permission anywayzSmile
Quote Reply
Re: [stu2000] Top Ten list of links by hits on home page In reply to
I don't think that you ever had any intention of claiming the code as your own. It was probably just something that you didn't pay much attention to one way or the other. As for the MODs on your forum (or any other place ), just provide a reference to the author and how to contact him/her.

It was brought to your attention and you responded in the appropriate manner. Case closed. Smile

PS: G-T has set the edit feature on these forums to like 30 minutes or so after the original post. Notice after you post a msg that there is an edit button on your post. That will go after about 30 minutes.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [stu2000] Top Ten list of links by hits on home page In reply to
I made the reasonable assumption that the tophits field might contain the value of the number of hits for this modification and tried to access that value using the line below:

$output .= "<tr><td>&nbsp;$count. <a href=\"$build_jump_url?ID=$id{$field}\">$name{$field}</a> $tophits{$field}</td></tr>\n";

From what I can tell, I'm making an incorrect assumption as to this variable and wondered if anyone might point me the right way on this...

Thanks ahead of time - Jon


Quote Reply
Re: [Tomcat] Top Ten list of links by hits on home page In reply to
Hi All,

Would anyone know how I can do the following:

1 - Change the link to point to the detailed page rather then the ext URL
2 - How I remove the number of hits that is desplayed - i.e.only want the link

Thanks in advance
Hamsterpants
Quote Reply
Re: [Hamsterpants] Top Ten list of links by hits on home page In reply to
1) If in templates, just edit link.html. And point it to something like;

<%build_root_url%>/Detailed/<%ID%><%build_extension%>

Something like that should give you a URL for each link to goto the detailed page for that link. I think <%detailed_url%> may also work...but I can't remember if that is only a LSQL feature....

2) In site_html_templates.pl, near the bottom, find;

$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;

and change to something like;

$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong>|;

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Top Ten list of links by hits on home page In reply to
Hi Andy,

Thanks for the reply....Not sure if I am juste being thick, but the changes that you have suggested, r they specifically for the top ten mod?

Thanks
Hamsterpants
Quote Reply
Re: [Hamsterpants] Top Ten list of links by hits on home page In reply to
Whoops...my boo boo. I thought you just wanted them for the generally Tongue

Sorry

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Top Ten list of links by hits on home page In reply to
no worries Sly....any idea on editing the top ten mod though, as per my first post??
Quote Reply
Re: [Hamsterpants] Top Ten list of links by hits on home page In reply to
Sorry, I have been away for ages, so don't know if the solution is still required.

CHANGE
<a href=\"$build_jump_url?ID=$id{$field}\">$name{$field}</a>

TO READ
<a href=\"$build_detail_url?ID=$id{$field}\">$name{$field}</a>

I think that should do it

Stu2000

- Top 100 forums / GT Links 2.0 websites -
Quote Reply
Re: [stu2000] Top Ten list of links by hits on home page In reply to
Also the COUNT tag produces the list order, i.e 1,2,3,4,5 and the tag $tophits{$field} produces the hits count, just remove these from the line of HTML to work.

Stu2000

- Top 100 forums / GT Links 2.0 websites -
Quote Reply
Re: [stu2000] Top Ten list of links by hits on home page In reply to
Hi I followed the correct procedure of installing the top 10 sites ..... everything is fine. but i noticed something wrong.

The site with the most number of hits (#1) is recording 76 hits.

Whereas if i browse through my site lists, I have seen lists getting more than 200 hits as well. So how come the 200 hits are not showing up on #1 and the 76 hits is showing up ???

am i missing somethings??

regards.
Can't draw it here ......,
Quote Reply
Re: [klashinkov_khan] Top Ten list of links by hits on home page In reply to
okay i got what was wrong ..... i just put 8 instead of 17 (after looking @ links.def i found there was no number 17 entry there and that this hits info was pointing to 8 - this may not be the case for other people out there)
Can't draw it here ......,
Quote Reply
Re: [stu2000] Top Ten list of links by hits on home page In reply to
Glad to hear you got it all sorted out in the end.