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

Help with Global code refinement please

Quote Reply
Help with Global code refinement please
Hello,
here is the code I use to pull out the links with the most visits and display them on the frontpage:

Code:

sub {
use GT::Date;
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');
$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 (['Distinct LinkID','Links.*'], $cond );
while ($link = $sth->fetchrow_hashref) {
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('linkshort', $link);
}
return $output;
}


The code is great, and all I would like to add, is the ability to specify from which categories to pull the links from, so links from unwanted categories will not appear.

Thanks in advance,
Brakkar
Quote Reply
Re: [brakkar] Help with Global code refinement please In reply to
Hi,

If you can pass the categoryid as the third parameter, below code should work

sub {
use GT::Date;
my ($output,$sth,$link);
my $days = shift;
my $limit = shift;

my $thiscat=shift;
my $date = GT::Date::date_get();
my $newdate = GT::Date::date_sub($date,$days);
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'

'CateogryID','=',$thiscat
);
$sth = $search_db->select (['Distinct LinkID','Links.*'], $cond );
while ($link = $sth->fetchrow_hashref) {
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('linkshort', $link);
}
return $output;
}


Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Help with Global code refinement please In reply to
Thanks,
but i'm not sure that I understand how to specify which categories to incude ?

Cordially,
Brakkar