Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Random Featured Link

Quote Reply
Random Featured Link
I have been using some code I found in the Plugins forum for a random link display on my home page:

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 I wanted to do is make the global check that the link is not only Validated ('isValidated' => 'Yes') but is Featured as well ('isFeatured' => 'Yes'). I tried:

sub {
my $db = $DB->table('Links');
my $total = $db->count ( 'isValidated' => 'Yes', 'isFeatured' => '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;
}

but it didn't seem to work.

Also, for some reason when I use this it will only display the full link.html and won't let me loop to use just some of the link options.

Any ideas? TIA!

--

Kriis
Quote Reply
Re: [kriis] Random Featured Link In reply to
Hi...try this;

Code:
sub {

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

}

I just tested it, and it appears to be working ok.

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 Featured Link In reply to
Thanks Andy! That did work to search only the Valid, Featured links. Muchly obliged. Smile

Would you be able to help me with the link components thing too? I didn't want the whole link.html display (just the Title and Description) but nothing seems to work.

--

Kriis
Quote Reply
Re: [kriis] Random Featured Link In reply to
You could try;

Code:
sub {

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

}

Then copy over link.html, and make a new template called rand_link.html. That SHOULD give you access to all the tags you need, so just keep the ones you wanna use for a random link.

Hopefully that will work Smile

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 Featured Link In reply to
Is there a way to use this code + SSI?


I would like to rotate links on static pages ...

Last edited by:

Payooo: Aug 16, 2002, 8:59 AM
Quote Reply
Re: [Payooo] Random Featured Link In reply to
I'm not really sure if this would be possible. I suppose you could setup LSQL to build an extra page, and then on that page only include the tag for the global (with the code above)...its quite hypothetical really, but I would imagine it could work :)

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 Featured Link In reply to
Actually I am using an SSI call for it now:

<!--#include virtual="/db/page.cgi?p=random"-->

The only problem is that you get the entire link.html file displayed and can't pick and choose the elements you want. Otherwise it works brilliantly.

--

Kriis
Quote Reply
Re: [kriis] Random Featured Link In reply to
Just for anyone who wants to call it via SSH, you should be able to use the attached script ok. Just save it, and upload to the folder where add.cgi etc is.

You also need to edit the /full/path/to/admin bits, to reflect the location to your admin folder.

To call, just use;

<!--#exec cgi="/cgi-bin/new_links/randomprod.cgi"-->

Enjoy Smile

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 Featured Link In reply to
Hi, I found this thread while searching through trying to find a way of doing exactly this - displaying a random link on my homepage.

I uploaded the cgi script and also made the global but I'm getting a message on the screen saying [an error occurred while processing this directive]

I'm getting the same problem when trying to pull in the 5 latest topics from the forums - I've posted a similar post in the forum discussion thread but I'm just hoping someone can shed some light on this problem for me.

I've made sure the directory has .htaccess and have used a virtual path and an absolute path but neither works, I get the same message each time.

Any help would be great
Thanks
Sal
Quote Reply
Re: [SalB] Random Featured Link In reply to
Hi Sal,

Please ensure that your scripts are running properly before calling it via SSI. Ex, just check them directly on the browser location like http://www.../cgi-bin/new_links/randomprod.cgi

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Random Featured Link In reply to
HI Tandat,

well I just tried that and the randomprod.cgi I cannot get to work, am just getting an internal server error page come up - the other one for the forum is working perfectly when calling the cgi script.

I'm really no technical expert so I've tried the few things I know of to get a script running but nothing is working - uploaded correctly, correct paths in the script and correct permissions set on it (755) and that is the extent of my knowledge I'm afraid.

Cheers
Sal
Quote Reply
Re: [SalB] Random Featured Link In reply to
Hi,

I don't know what is yours but make sure two below lines should be changed to sutable values on your server

Code:
use lib '/full/path/to/admin';
...
Links::init('/full/path/to/admin');

Hope that helps!

Chees,

Cheers,

Dat

Programming and creating plugins and templates
Blog