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

Re: [Eraser] FatherID with Global

Quote Reply
Re: [Eraser] FatherID with Global In reply to
Hi,

This is TOTALLY untested:

get_rand_from_top_cat
Code:
sub {

my $current_cat_id = $DB->table('CatLinks')->select( ['CategoryID'], { LinkID > $_[0] } )->fetchrow;
my $cat_name = $DB->table('Category')->select( ['Full_Name'], { ID => $current_cat_id } )->fetchrow;

my @tmp = split /\//, $cat_name;
pop @tmp;

my $higher_up_cat = $DB->table('Category')->select( ['ID'], { Full_Name => join('/',@tmp) } )->fetchrow;

my $all_ids = $DB->table('Category')->children($higher_up_cat);
push @$all_ids, $higher_up_cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options("ORDER BY RAND() LIMIT 6");

my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ID','!=',$_[0]);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

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

return { relatedlinks => \@links };
}

..call with:

Code:
<%get_rand_from_top_cat($ID)%>
<%if relatedlinks.length%>
<%loop relatedlinks%>
<%include link.html%>
<%endloop%>
<%endif%>

Just be sure you don't just overwrite your old global from the template, in case its not what you want (I'm gonna call it a day in a min, as its gone 8pm ;))

Best bet, is to set it up - just in the footer of detailed.html, so you can see what it looks like / if it works =)

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 FatherID with Global Eraser 4320 Aug 2, 2008, 6:31 AM
Thread Re: [Eraser] FatherID with Global
Andy 4220 Aug 2, 2008, 7:06 AM
Thread Re: [Andy] FatherID with Global
Eraser 4230 Aug 2, 2008, 8:14 AM
Thread Re: [Eraser] FatherID with Global
Andy 4208 Aug 2, 2008, 8:40 AM
Thread Re: [Andy] FatherID with Global
Eraser 4215 Aug 2, 2008, 11:54 AM
Thread Re: [Eraser] FatherID with Global
Andy 4216 Aug 2, 2008, 12:11 PM
Post Re: [Andy] FatherID with Global
Eraser 4208 Aug 2, 2008, 12:14 PM