Gossamer Forum
Home : Products : Gossamer Links : Discussions :

randon plugin on subcategories pages

Quote Reply
randon plugin on subcategories pages
I am using the following Global to display a random link in the rightsidebar (SQL Links 3.2+)

Now this Global works on homepage and on the detailed pages of the links but not when displaying the subcategories!

sub {
my $db = $DB->table('Links');
my $total = $db->count ( 'isValidated' => 'Yes' );
my $rand = int( rand($total) );
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select->fetchrow_hashref;
my $html = Links::SiteHTML::display('link', $link);
return $html;
}


what is wrong with it?

Thanks
Antoine
Quote Reply
Re: [antoined] randon plugin on subcategories pages In reply to
Mmm..I can't see any reason it wouldn't work...

so it just doesn't show the random link?

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] randon plugin on subcategories pages In reply to
it only generates a number every time different!

I know it's very strangeUnsure

Antoine
Quote Reply
Re: [antoined] randon plugin on subcategories pages In reply to
Hi,

Sorry, not sure what you mean. So you are saying it only returns a number, and not the link?

This will also do the trick:

Code:
sub {
my $db = $DB->table('Links');
$db->select_options ("ORDER BY RAND() LIMIT 1");
my $link = $db->select( { isValidated => 'Yes' } )->fetchrow_hashref;
my $html = Links::SiteHTML::display('link', $link);
return $html;
}


..although, this isn't quite as effiecient if you have a very large database :)

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] randon plugin on subcategories pages In reply to
For anyone interested - I've fixed this.

The global was called "random", so I renamed to "random_link", and it works perfectly now (I guess <%random%> is a tag thats used in the category template, so it wasn't actually calling the global :))

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!