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

Re: [AMIXIMA] Links Custom Sort

Quote Reply
Re: [AMIXIMA] Links Custom Sort In reply to
Hi,

Took a little while to do, but here you go:

load_links
Code:
sub {

my ($limit,$sort_order,$cat_id) = (shift,shift,shift);
my @queries = @_;

$sort_order ||= "Title ASC";

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

if ($limit) {
$tbl->select_options(qq|ORDER BY $sort_order LIMIT $limit|);
} else {
$tbl->select_options(qq|ORDER BY $sort_order|);
}

my $cond = new GT::SQL::Condition;

foreach (@queries) {
my ($field,$operator,$val) = split /::/;
$cond->add($field,$operator,$val);
}
$cond->bool("AND");

my $sth = $tbl->select( $cond, { 'CatLinks.CategoryID' => $cat_id } ) || die $GT::SQL::error;

my @loop;
while (my $hit = $sth->fetchrow_hashref) {

$hit = Links::SiteHTML::tags('link', $hit);
push @loop, $hit;
}

return { cond_loop_link => \@loop }


}


Call with:

Code:
<%load_links(LIMIT,'SORT ORDER',CATEGORY_ID,'isValidated::=::Yes','Foo::LIKE::%bar%')%>

...so a "proper" example:

Code:
<%load_links(10,'Title ASC',123,'isValidated::=::Yes','Foo::LIKE::%bar%')%>

..which would get links from category ID 123, sorted by Title ASC and limit it to 10. It would also look for:

Code:
isValidated => Yes
Foo LIKE "%bar%"

If you are calling this from inside a category that you wanna get the results from, you can use $category_id in the place of 123.

To show the results you just do:

Code:
<%loop cond_loop_link%>
<%include link.html%>
<%endloop%>

Hope that helps.

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!
Subject Author Views Date
Thread Links Custom Sort AMIXIMA 4130 Feb 8, 2012, 9:59 AM
Thread Re: [AMIXIMA] Links Custom Sort
Andy 4028 Feb 9, 2012, 12:46 AM
Thread Re: [Andy] Links Custom Sort
AMIXIMA 4025 Feb 9, 2012, 1:02 AM
Thread Re: [AMIXIMA] Links Custom Sort
Andy 4030 Feb 9, 2012, 1:35 AM
Thread Re: [Andy] Links Custom Sort
AMIXIMA 4023 Feb 9, 2012, 10:59 AM
Thread Re: [AMIXIMA] Links Custom Sort
Andy 4011 Feb 10, 2012, 3:38 AM
Post Re: [Andy] Links Custom Sort
AMIXIMA 3987 Feb 13, 2012, 10:03 AM