Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Radom links with images

Quote Reply
Radom links with images
I searched the forums for this, but can't quite find an answer.

Can someone tell me how I can display several random links (say 12) with their respective images on the index page?

I would like it to show 12 random links, with each link's image placed beside it with a small description. is this possible?
Quote Reply
Re: [peego] Radom links with images In reply to
Here’s what I use:

You will need:
1/ Global > “link_logo_random
2/ Template > “link_logo_random.html
3/ Column in your links table > “Logo
4/ Modify > “home.html” template.

Place the following into your “Template Globals” in the Admin area.
NB: Change the “LIMIT 10” in the global to the amount you want to display.

sub {
my $link_db = $DB->table('Links');
$link_db->select_options ("ORDER BY rand()","LIMIT 10");
my $sth = $link_db->select ({isValidated => 'Yes' });
my $output;
while (my $link = $sth->fetchrow_hashref){
$output .= Links::SiteHTML::display ('link_logo_random', $link);
}
return $output;
}

Make up a template link_logo_random.html which has the following in it:
<%if Logo%>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank">
<img src="<%build_images_url%>/logo/<%Logo%>" border="0" width="120" height="90"></a>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><%Title%></a>
<%endif%>

This shows the Title and Logo, you can change it to Description.

Then up load that template to your "local" template directory.

Place the following tag in your home.html template.
<%random_link_logo%>

NB: Make sure you have at least 10 links that have logo’s to display and they are in the correct directory on your server.

The global will pull the logo’s from the link_logo_random.html template and display them where you place the <%random_link_logo%> tag.

Regards

minesite
Quote Reply
Re: [minesite] Radom links with images In reply to
that worked great, thanks minesite!

quick question, is there a way to get these random links w/ image to show up in 2 columns instead of 1.

so its like this:

Random link 6 [IMAGE1] Random link 1 [IMAGE2]
Random link 7 [IMAGE1] Random link 2 [IMAGE2]
Random link 8 [IMAGE1] Random link 3 [IMAGE2]
Random link 9 [IMAGE1] Random link 4 [IMAGE2]
Random link 10 [IMAGE1] Random link 5 [IMAGE2]
Quote Reply
Re: [peego] Radom links with images In reply to
I’m not sure the best way but you could limit the global to only display 5 links
and then call the global twice.
Column 1 <%link_logo_random%> Column 2 <%link_logo_random%>

Or set up a second global
Column 1 <%link_logo_random%> Column 2 <%link_logo_random2%>
Unless you have lots of logo’s to display you will get duplicates.

The other option is to do a search for “if row_num” this is used to display links
in 2 columns so should work for this application.

Someone else may be able to help further.

Regards

minesite
Quote Reply
Re: [minesite] Radom links with images In reply to
i created a 2nd random link and that works Laugh thanks!