Gossamer Forum
Home : Products : Links 2.0 : Customization :

Top 10 on home page by number of visits

(Page 1 of 5)
> >
Quote Reply
Top 10 on home page by number of visits
Hi

I know this has been answered again and again but I need to know step by step how to put top 10 sites on main page by number of visits without using SSI? (i'm using links 2.0 & templates) Please help... i'll be REALLY thankful. I was trying to follow this thread http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/002409.html but got lost.
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Replace your site_html_home in site_html_templates.pl with:
Code:
sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
my (@data,%tophits,%name,%url);

open (NAME,"<$db_file_name");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
$topsites_output .= "$count. <a href=\"$url{$field}\">$name{$field}</a><br>\n";
}
$count++;
}


return &load_template ('home.html', {
topsites_output => $topsites_output,
category => $category,
grand_total => $grand_total,
%globals
});
}

Then in home.html, put <%topsites_output%> wherever you want the info.

------------------
Quote Reply
Re: Top 10 on home page by number of visits In reply to
THANKX A MILLION CEGlobe!!!! It's working!!!! but I noticed that instead of using the jump cgi the links are coded with real urls...

can u please make the links coded with the jump.cgi?ID=xxx because i don't want people to be looking at the real urls!!! This is only change i need... the rest is absolutely fine!!

Thanks again! I really appreciate your help!

Deep Impact
Quote Reply
Re: Top 10 on home page by number of visits In reply to
change:
<a href=\"$url{$field}\">

to:

<a href=\"/path/to/jump.cgi?ID=$field\">

------------------
Quote Reply
Re: Top 10 on home page by number of visits In reply to
THANKS!!! It's working just as i wanted it to Smile

Deep Impact
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Hi,

Can this same change be applied to the e-mail so that when this is sent it will go to the link via jump, rather than showing the URL in the e-mail

Thanks
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Hi !!!

Great job Ceglobe !!!

But there is a problem .... the mod shows the links in a random order ...

like this :

1. Jonas ( 1 hits)
2. Carlos ( 3 hits)
3. Joaquim ( 10 hits)
4. Zeca ( 8 hits)
5. Tatu ( 6 hits )

when the correct should be :

1. Joaquim ( 10 hits)
2. Zeca ( 8hits)
3. Tatu ( 6 hits)
4. Carlos ( 3 hit)
5. Jonas ( 1 hit )

Please, can someone help me to fix this ???

Regards,

Marco Aurélio

Quote Reply
Re: Top 10 on home page by number of visits In reply to
I have installed the Top 10 on all of my pages except, category, rate_top, new, cool, and search results. Everything is working great except I have added a new file in my templates. It builds the template fine, but it is prints the top 10 twice. The page does not building any links on it as in category, search results, etc. Any ideas on what I have done wrong? Here is the code in the site_html_templates.pl
Code:
sub site_html_rate_info {
# --------------------------------------------------------
# Rate Info File
my (@data,%tophits,%name,%url);

open (NAME,"<$db_file_name");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
$topsites_output .= "$count. <a href=\"http://www.homewithgod.com/cgi-homewithgod/links/jump.cgi?ID=$field\">$name{$field}</a><br>\n";
}
$count++;
}


return &load_template ('rate_info.html', {
topsites_output => $topsites_output,
%globals
});
}

BTW Thanks, CEGlobe and Eliot for the Mod and instructions on top 10 and adding new templates!

------------------
Jimmy Crow
www.homewithgod.com
webmaster@homewithgod.net


[This message has been edited by jcrow (edited March 18, 2000).]
Quote Reply
Re: Top 10 on home page by number of visits In reply to
The problem is that you have hacked the codes too much and with the current definitions you have, it will not work.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Top 10 on home page by number of visits In reply to
yeah I tried a lot of different things to make it work. I guess I'm not clear on what you would use the extra templates for. Would they only be used for calling simple tags like <%category%>, <%query%>, etc. ? Is the only way to call <%topsites_output%> by inserting it on a template in the templates file without doing a lot of modification to the code?

Thank you for your time Smile

------------------
Jimmy Crow
www.homewithgod.com
webmaster@homewithgod.net


[This message has been edited by jcrow (edited March 18, 2000).]
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Yes....try the following:

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

Code:
sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites

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[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
$output .= "$count. <a href=\"$url{$field}\">$name{$field}</a><br>\n";
}
$count++;
}
return $output;
}

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

Code:
topsites => &top_ten

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

Code:
<%topsites%>

That should do it.

Regards,



------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums


[This message has been edited by AnthroRules (edited March 18, 2000).]
Quote Reply
Re: Top 10 on home page by number of visits In reply to
YES! That works perfect and on the first try! Am I correct to assume that this can only be used in files that are in your template directory and not on pages I have made and uploaded in the Links/Pages directory. This did exactly what I wanted it to do. You never cease to amaze me at how fast you can write these codes. Thank you very much.



------------------
Jimmy Crow
http://www.homewithgod.com
webmaster@homewithgod.net
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Ok Guys ,

This mod run perfectly, but don't match the order to links that have more hits ... why ???

Take a look in my post above ...

Any suggestion, Eliot, Jimmy ???

Thanks,

Marco Aurélio
Quote Reply
Re: Top 10 on home page by number of visits In reply to
jcrow,

Code:
#!/usr/local/bin/perl
# Script for putting Top Ten Sites in other LINKS associated pages.
# Change the permission of this script to 755.
# Change the path to the links.cfg file if you need to.
# Use it in the following manner:
# <!--#exec cgi="/cgi-bin/links/topsites.cgi"--> in SSI capable
# pages.
###########################################################
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script locatio
n: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script locatio
n: Windows \

require "admin/links.cfg"; # Change this to full path to links.c
fg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set
correctly.";
exit;
}
#========================================================
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[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
$output .= "$count. <a href=\"$url{$field}\">$name{$field}</a><br>\n";
}
$count++;
}
return $output;
}

Then add the following codes in your SSI enabled pages:

Code:
<!---#exec cgi="/cgi-bin/links/topsites.cgi"-->

Regards,





------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Top 10 on home page by number of visits In reply to
marcoBR,

Your problem is that you need to change the field numbers for the following variable configs:

Code:
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];

Translations:

$tophits -> You need to change [8] to the number of your Hits field.

$name -> You need to change [1] to the number of your Title field.

$url -> You need to change [2] to the number of your URL field.

Most likely you do not have the correct field numbers for these variables, which is screwing up the sorting.

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Top 10 on home page by number of visits In reply to
marcoBR
I currently have both of these mods installed, CEGlobe's works fine on all pages except where it builds links. And they are in order. Eliot's version works fine on All of the pages including those that builds links. Have you tried installing his version? It is pretty simple and takes a few minutes. You must have copied something incorrectly in CEGlobes because it is working here or, I'm not real smart at this, but you might check your sorting fields. Someone will probably come and correct me, but that is where I would look if both versions are not working.

------------------
Jimmy Crow
http://www.homewithgod.com
webmaster@homewithgod.net
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Hey thanks a lot Eliot, the stand alone pages was what I was referring to in my last statement. I am currently changing my site to blend in with my links design and was thinking that I would have to make templates for all of the pages. This will save me MANY hours work! Smile

Jimmy

------------------
Jimmy Crow
http://www.homewithgod.com
webmaster@homewithgod.net
Quote Reply
Re: Top 10 on home page by number of visits In reply to
YEAH !!!

Now all is working perfectly !!!

Thanks Eliot and Jimmy ...

Marco Aurélio
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Good for both of you...Glad it is working for you both.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Top 10 on home page by number of visits In reply to
jcrow,

BTW: If you want to use the jump.cgi file (which I personally would not recommend since people could just continually click on the Top Sites therefore leaving a static list of "top sites") in this Mod, just do the following:

1) Add the following codes:

Code:
$id{$data[0]} = $data[0];

AFTER the following codes:

Code:
$tophits{$data[0]} = $data[8];

2) Then edit the following line of codes:

Code:
$output .= "$count. <a href=\"$url{$field}\">$name{$field}</a><br>\n";

to look like the following:

Code:
$output .= "$count. <a href=\"$build_jump_url?ID=$id{$field}\">$name{$field}</a><br>\n";

Again, I would recommend NOT using the jump.cgi, because the Top Ten could become biased and scewed.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums


[This message has been edited by AnthroRules (edited March 18, 2000).]
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Very Good !!!

Is it possible to include new output fields like description, images, etc ... in this mod ??

-> Here: $output .= "$count. <a href=\"$build_jump_url?ID=$id{$field}\">$name{$field}</a><br>\n";

Any ideas?

Regards,

Marco Aurélio
Quote Reply
Re: Top 10 on home page by number of visits In reply to
uh...yeah...think out of the box (codes), please...

Look at the relationships of the codes I posted and the Mod...see anything that sticks out when I added the jump.cgi option???

Come on, people...let's think a little here. The codes you need are right in front of you.

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Is it possible to limit the number of characters in the titles of the tpo ten on the home page without affecting the title in the rest of links. I am putting the top 10 on my hompepage in a fairly narrow table and as it is now, some of the titles take up 2 and 3 lines.

------------------
Jimmy Crow
www.homewithgod.com
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Code:
$title = substr($title,0,8) . "..." if (length($title) > 8);

Try the above codes. These will work with your "title" variable. Change $title to whatever you are using in this Mod.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Top 10 on home page by number of visits In reply to
Thank you for all your help on this. I have tried inserting the code in 4 different places in between open and close name and in the output area. I appoligize for knowing, but I'm still a rookie. When you have a chance could you point me where it goes.

------------------
Jimmy Crow
www.homewithgod.com
> >