Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Most popular links from the last XX days only global ?

Quote Reply
Most popular links from the last XX days only global ?
Hello
I thought about an exiting new global and I would really appreciate your help on creating it. I don’t know if it’s possible but shouldn’t be too complicated. I tried to search but couldn't find it.

Roughly, I would like this global to display the most popular links from the latest month. It would require:

-Use links where added date is no older than xx days (lets say 30).
-Sort them by hits, descending
-Cut the number of links displayed to yy (lets say the first 5).
-Allow to specify a style for links (lets say links2.html user template).

Thanks in advance,
Brakkar
Quote Reply
Re: [brakkar] Most popular links from the last XX days only global ? In reply to
Hi,

That would only show the most popular new links. If you want to show the most popular links from the last xx days you can use my ExtraStats plugin.

If you really only want the most popular new links, something like this should do:

sub {
my ($output,$sth,$link);
my $days = shift;
my $limit = shift;
my $date = GT::Date::date_get();
my $newdate = GT::Date::date_sub($date,$days);
my $search_db = $DB->table('Links');
$search_db->select_options ("ORDER BY Hits DESC","LIMIT $limit");
my $cond = GT::SQL::Condition->new( 'Add_Date', '>', $newdate, 'isValidated', '=', 'Yes');
$sth = $search_db->select ($cond);
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link2', $link);
}
return $output;
}

You'll need to call it with <%globalname('7','10')%> to show the 10 most popular links which have been added over the last 7 days.
Quote Reply
Re: [afinlr] Most popular links from the last XX days only global ? In reply to
Thanks for your answer, but all I get is:"Undefined subroutine >::Date::date_get called at (eval 8) line 5."Do I need to install your plugin in order to have this code working ?
Thanks,
Brakkar

Quote Reply
Re: [brakkar] Most popular links from the last XX days only global ? In reply to
No you don't need the plugin for this global.

Try adding the line

use GT::Date;

at the beginning of the global.
Quote Reply
Re: [afinlr] Most popular links from the last XX days only global ? In reply to
Well, it seems to work fine !!
Thank you so much. This is a cool feature !!

Brakkar
Quote Reply
Re: [afinlr] Most popular links from the last XX days only global ? In reply to
Hello,

do you think it would be possible to EXCLUDE a category (ID) from the entire process ?
What should I add to the global ?

Thanks in advance,

Brakkar
Quote Reply
Re: [brakkar] Most popular links from the last XX days only global ? In reply to
Not sure if this will work, but try;

Code:
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY Hits DESC","LIMIT $limit");
my $cond = GT::SQL::Condition->new( 'Add_Date', '>', $newdate, 'isValidated', '=', 'Yes');
my $cond2 = GT::SQL::Condition->new( 'ID', 'NOT LIKE', '12345');
$sth = $search_db->select ($cond, $cond2);

Cheers

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: [brakkar] Most popular links from the last XX days only global ? In reply to
I think the easiest way to do this would be to add a new column to the Category table. Something like showNew set to enum, 'Yes','No'.

Then you'll need to change the global slightly

sub {
my ($output,$sth,$link);
my $days = shift;
my $limit = shift;
my $date = GT::Date::date_get();
my $newdate = GT::Date::date_sub($date,$days);
my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ("ORDER BY Hits DESC","LIMIT $limit");
my $cond = GT::SQL::Condition->new( 'Add_Date', '>', $newdate, 'isValidated', '=', 'Yes', 'showNew', '=', 'Yes');
$sth = $search_db->select ($cond);
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link2', $link);
}
return $output;
}
Quote Reply
Re: [Andy] Most popular links from the last XX days only global ? In reply to
You beat me again Wink - and your suggestion is much easier. You could just put the two condition statements together though and as far as I remember you want CategoryID rather than ID from the CatLinks table. Also not sure about using NOT LIKE rather than <> or != - any reason for this?

Code:
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY Hits DESC","LIMIT $limit");
my $cond = GT::SQL::Condition->new( 'Add_Date', '>', $newdate,
'isValidated', '=', 'Yes', 'CategoryID', '<>', '12345');
$sth = $search_db->select ($cond);
Quote Reply
Re: [afinlr] Most popular links from the last XX days only global ? In reply to
LOL!

I wasn't sure if putting them together would give the right result, so I just made 2 seperate statements Tongue

Cheers

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!