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

Random links by Link_Owner

Quote Reply
Random links by Link_Owner
I need a global to display 4 random links by the same Link_Owner on the detailed page similar to the one I have for just random links:

Code:
sub {
my (@links,$sth,$link);
my $tags = shift;
my ($cat_id, $cat_name) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ("ORDER BY RAND()","LIMIT 4");
my $sth = $link_db->select ( { CategoryID => $cat_id }, {isValidated => 'Yes'});
while (my $link = $sth->fetchrow_hashref) {
$link = Links::SiteHTML::tags('link', $link);
push@links, $link;
}
return {relate=>\@links};
}

I'm just not sure how to make the above show only links by the same Link Owner?

Thanks!

Anthony
Quote Reply
Re: [anthonyweston] Random links by Link_Owner In reply to
Hi,

Try changing:

Code:
my $sth = $link_db->select ( { CategoryID => $cat_id }, {isValidated => 'Yes'});

to

Code:
my $sth = $link_db->select ( { CategoryID => $cat_id }, {isValidated => 'Yes', LinkOwner => $tags->{LinkOwner} });

That should do it =)

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: [Andy] Random links by Link_Owner In reply to
Thanks. Something appears to be wrong with doing that,

I get:

Quote:
A fatal error has occured:
Can't use string ("0") as a HASH ref while "strict refs" in use at (eval 618) line 4.
Also, I don't really need it to be the same category, that bit could be scrapped?

Thanks!

Anthony
Quote Reply
Re: [anthonyweston] Random links by Link_Owner In reply to
Hi,

In that case, try:
Code:
sub {
my @links;
my $link_db = $DB->table('Links');
$link_db->select_options ("ORDER BY RAND()","LIMIT 4");
my $sth = $link_db->select ( {isValidated => 'Yes', LinkOwner => $_[0] });
while (my $link = $sth->fetchrow_hashref) {
$link = Links::SiteHTML::tags('link', $link);
push @links, $link;
}
return {relate=>\@links};
}

Then call with:

Code:
<%global_name($LinkOwner)%>

Hopefully that should work (untested)

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: [Andy] Random links by Link_Owner In reply to
Thanks again. It now doesn't cause an error but no links are returned in the place of the global and there are definitely other links validated.
Quote Reply
Re: [anthonyweston] Random links by Link_Owner In reply to
Where are you calling it from, and with what code? I can't see any reason it wouldn't work (apart from if you didn't pass $LinkOwner, as in my example)

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: [Andy] Random links by Link_Owner In reply to
I've called the global rand_channel and used your code:

Code:
sub {
my @links;
my $link_db = $DB->table('Links');
$link_db->select_options ("ORDER BY RAND()","LIMIT 4");
my $sth = $link_db->select ( {isValidated => 'Yes', LinkOwner => $_[0] });
while (my $link = $sth->fetchrow_hashref) {
$link = Links::SiteHTML::tags('link', $link);
push @links, $link;
}
return {relate=>\@links};
}
Then on the detailed page (by the way, it's in static mode if that makes a difference) I have used:

Code:
<%rand_channel($LinkOwner)%>
Quote Reply
Re: [anthonyweston] Random links by Link_Owner In reply to
Are you running the loop after? Whistle

i.e

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

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: [Andy] Random links by Link_Owner In reply to
That would have been a good idea Blush

Thanks, working!

Appreciate your help.