Gossamer Forum
Home : Products : Gossamer Links : Discussions :

how to display the top 10 for each main category

(Page 1 of 2)
> >
Quote Reply
how to display the top 10 for each main category
Hi. How to display the top 10 and the last 10 links for each main category like hotscripts?

see hotscripts.com / New listing , Top Rating and Most Popular

For example, in a new template, how to display the same results like hotscripts for each main category?

In other words, this global works fine and display the most popular 10 links in each category, but How I can modify this global to display in another template the most popular links (by hits, or by another field add_date, etc.) only for one category, for example the id=4. ??


sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table ('Links','CatLinks');
$db->select_options ('ORDER BY Hits DESC', 'LIMIT 10');
my $sth = $db->select ( { 'CatLinks.CategoryID' => $id}, ['Links.ID', 'Links.Title', , 'Links.URL'], { isValidated => 'Yes'} );

my $popularcategory;
while (my ($id,$name,$url) = $sth->fetchrow_array) {

$popularcategory .= "<a href='$url'>$name</a><br>";
}
return $popularcategory;
}



Thank you very much.
Quote Reply
Re: [pedroguerra] how to display the top 10 for each main category In reply to
Hi,

You can do:

Code:
sub {
my $id = shift;
my $db = $DB->table ('Links','CatLinks');
$db->select_options ('ORDER BY Hits DESC', 'LIMIT 10');
my $sth = $db->select ( { 'CatLinks.CategoryID' => $id}, ['Links.ID', 'Links.Title', , 'Links.URL'], { isValidated => 'Yes'} );
my $popularcategory;
while (my ($id,$name,$url) = $sth->fetchrow_array) {
$popularcategory .= "<a href='$url'>$name</a><br>";
}
return $popularcategory;
}

and then do <%popular (4)%> to display popular links in category id 4, or <%popular ($ID)%> to display popular links in category <%ID%>.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] how to display the top 10 for each main category In reply to
Alex:

short of changing $url to 'http://www.sitename.com/cgi-bin/links/jump.cgi?ID=$id' is there a smarter way of doing it?

The reason I believe it is better to use jump.cgi than the actual url is that the popular programs will continue to be tracked should they be clicked on. (Of course there are arguments to the contrary, but I won't discuss them here).

Also, what would be the best way to include a variable should there be less than 10 links in one category. For example, if there are only 3 links in one category, and you list all 3 as being popular it would seem not to be all that helpful.

I was thinking there must be a way to do a <%if abc > '10'%> <%poplular ($ID)%><%endif%>.

Hope I am making sense here! Blush

Thanks,



Clint.
--------------------------
http://AffiliatesDirectory.com
The Affiliate Programs Directory

Last edited by:

Clint: Apr 4, 2002, 2:29 PM
Quote Reply
Re: [Clint] how to display the top 10 for each main category In reply to
Clint , the following may help.





<%new_by_cat%>

sub {

# Displays New links by category.

my ($output,$sth,$link);

my $id = shift;

my $db = $DB->table ('Links','CatLinks');

$db->select_options ('ORDER BY ADD_DATE DESC', 'LIMIT 10');

my $sth = $db->select ( { isNew => 'Yes'}, { 'CatLinks.CategoryID' => $id}, { isValidated => 'Yes'} );

my $premium;

while ($link = $sth->fetchrow_hashref) {

$output .= Links::SiteHTML::display ('link7', $link);

}

return $output;

}






<%popular_by_cat%>


sub {

# Displays the most popular links per category.

my ($output,$sth,$link);

my $id = shift;

my $db = $DB->table ('Links','CatLinks');

$db->select_options ('ORDER BY Hits DESC', 'LIMIT 10');

my $sth = $db->select ( { 'CatLinks.CategoryID' => $id}, { isValidated => 'Yes'} );

my $premium;

while ($link = $sth->fetchrow_hashref) {

$output .= Links::SiteHTML::display ('link7', $link);

}

return $output;

}






And call it as Alex mention above by:

<%popular_by_cat (4)%> to display popular links in category id 4,

or <%popular_by_cat ($ID)%> to display popular links in category <%ID%>.




Change 'LIMIT 10' to required number

Change template 'link7' to suit your output style.

Link7.html Template may look like this:

<table><tr><td>

<b><font size="1">

<a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><%Title%>

</a></font></b>

</td></tr></table>

Regards

minesite
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
Hi minesite

I tried the code you provided, and I got the following error:

Quote:
GT::Config (714): Unable to compile 'new_by_cat' in file '/home/httpd/html/cgi-bin/linkssql210/admin/templates/default/globals.txt': Bareword "isValidated" not allowed while "strict subs" in use at (eval 10) line 7.
at /home/httpd/html/cgi-bin/linkssql210/admin/GT/Template.pm line 461.

Did I mess up something??

Thanks very much. Smile

------------------------------------------
Quote Reply
Re: [DogTags] how to display the top 10 for each main category In reply to
DogTags

It may be messed up in the post, I'll try again.

sub {
# Displays New links NAME ONLY by category.
my ($output,$sth,$link);
my $id = shift;
my $db = $DB->table ('Links','CatLinks');
$db->select_options ('ORDER BY ADD_DATE DESC', 'LIMIT 10');
my $sth = $db->select ( { isNew => 'Yes'}, { 'CatLinks.CategoryID' => $id}, { isValidated => 'Yes'} );
my $premium;
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link7', $link);
}
return $output;
}

Called by <%new_by_cat ($ID)%>

my $sth = $db->select ( { isNew => 'Yes'}, { 'CatLinks.CategoryID' => $id}, { isValidated => 'Yes'} );

The above is all one line my $sth =.......{ isValidated => 'Yes'} );

Regards

minesite
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
Hi minesite

I'm giving it a try, but I keep getting an error:
Quote:
GT::Config (737): Unable to compile 'new_by_cat' in file '/home/httpd/html/cgi-bin/linkssql210/admin/templates/default/globals.txt': Bareword "isValidated" not allowed while "strict subs" in use at (eval 10) line 7.
at /home/httpd/html/cgi-bin/linkssql/admin/GT/Template.pm line 461.

I get this right off the bat.

I'm using LinksSQL 2.10 if that makes any difference.

Thanks! Smile

------------------------------------------
Quote Reply
Re: [DogTags] how to display the top 10 for each main category In reply to
I'm using 2.10 so I'm not sure what the problem is, you could try taking out the , { isValidated => 'Yes'} and test it.

I'm presuming you have the "isValidated" column, and calling it exactly like this <%new_by_cat ($ID)%> in your category template.






my $sth = $db->select ( { isNew => 'Yes'}, { 'CatLinks.CategoryID' => $id} );




Regards

minesite
Quote Reply
Re: [Alex] how to display the top 10 for each main category In reply to
This global does not work for my. If I put exactly
<%popularcategory (4)%>
does not appear at all in static or dynamic pages.
If I use
<%popularcategory ($ID)%>
does not appear at all either.
If I use
<%popularcategory (4) %>
appears: "Unknow tag"

Someone can like solve this?

Thanks
Quote Reply
Re: [pedroguerra] how to display the top 10 for each main category In reply to
Hi Pedroguerra

Paste your global so we can have a look.

Regards

minesite

Last edited by:

minesite: Apr 18, 2002, 11:55 AM
Quote Reply
Re: [pedroguerra] how to display the top 10 for each main category In reply to
Did you created a popularcategory global and pasted the codes other provided for you above?
IF you did not create the popularcategory global, that is the reason you get unknown tag error.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] how to display the top 10 for each main category In reply to
 
The global is the provided by Alex in the second post of this thread. Global called popularcategory.
I added this global and next I put the <%popularcategory%> codes.

This global works for you??

Thank you very much.
Quote Reply
Re: [pedroguerra] how to display the top 10 for each main category In reply to
I did not try it yet, but the way you described how you inserted it, should work for you.

Try following:
Check the default template in the config.
You should insert the global into the correct template selection.

Check it. I think this is the problem, but this is my last idea.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [pedroguerra] how to display the top 10 for each main category In reply to
I just tried it on my site and it works. no problem.

Regards

minesite
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
 
Thanks minesite, but in my site dont work:
What tag you have used?

I have test the Alex global in category.html template with:

<%popular (4)%> ;nothing happens
<%popularcategory (4)%> :nothing happens
<%popularcategory(4)%> :Unknown Tag: 'popularcategory(265)'

I dont know what is the problem.
I have test all tags only in dinamyc pages.

What is your opinion??

Thank you very much.
Quote Reply
Re: [pedroguerra] how to display the top 10 for each main category In reply to
If you have called the global popularcategory, use the tag below.

Do not change it, do not put in (4).

<%popularcategory ($ID)%>

Regards

minesite
Quote Reply
Re: [Alex] how to display the top 10 for each main category In reply to
What would it take to display the "last ten" links inserted in a "main category" (right under the root) instead of the "top ten".



Thank you for your time. Smile

Cheers.
Quote Reply
Re: [nt6] how to display the top 10 for each main category In reply to
Try:


sub {



# Displays the newest links added to the site.

my ($output,$sth,$link);

my $search_db = $DB->table('Links');

$search_db->select_options ('ORDER BY ADD_DATE DESC', 'Limit 10');

$sth = $search_db->select ( { isNew => 'Yes'});

while ($link = $sth->fetchrow_hashref) {

$output .= Links::SiteHTML::display ('link1', $link);

}

return $output;

}






Call the Global newlinks and in home or category template call it via

<%newlinks%>

Will require a link1.html template to suit the output required.

For the new links per category see top of this thread.


Regards

minesite
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
Thank you for your reply.

I guess I wasn't clear on what I was asking for.

I was asking for a global that does exactly the same as your global but is specific to each "main" category (right under the root) , and not all new links in the site. The global should display only last new links in the main category it is used in.



Thank you for your time.
Quote Reply
Re: [nt6] how to display the top 10 for each main category In reply to
Hi NT6

Is this what you are chasing ?


<%new_by_cat%>

sub {

# Displays New links by category.
If so look at the 4 th post in this thread.

Regards

minesite
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
CrazySorry I missed that.



But when I tried it, nothing came up in the page CrazyCrazy

I change the link template, but otherwise it's the same global.

I tried using this line

my $sth = $db->select ( { isNew => 'Yes'}, { 'CatLinks.CategoryID' => $id} );


but still nothing.

Any Ideas?
Quote Reply
Re: [nt6] how to display the top 10 for each main category In reply to
Use Alex's code on the 2nd post and get that working, if not use the following check list to narrow down the problem.
Don't do any changes to Alex's example until you have it working:

Have you put the global code into Admin>Build>Template Globals ?

Have you called it popular ?

Have you put <%popular ($ID)%> in category.html template ?

Do you have popular links in that category ?

Regards

minesite
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
I got Alex's global working fine.Smile

The only thing is this is a pop link in category global and not a last link in category global. Frown
Quote Reply
Re: [nt6] how to display the top 10 for each main category In reply to
Replace

ORDER BY Hits DESC

with

ORDER BY Add_Date DESC

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [minesite] how to display the top 10 for each main category In reply to
Hi,

Is it also possible to have more categories with new links included?
> >