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

Changing output in random links global

Quote Reply
Changing output in random links global
Hi, I am trying to change the global that selects three links at random
to diplay. This is the code:

sub {
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isValidated => 'Yes' });
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({ isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

I want to change it so that rather than outputing the link like it looks in link.html I can control the output and only show the title and description. An example of this would be the 'last 10 links' global. Here is code for that:

sub {
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Add_Date DESC', 'LIMIT 10');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
$link->{Description} = (length $link->{Description} > 70) ? substr($link->{Description},0,70) . ' ...' : $link->{Description};
push (@output, $link);
}
return { Lastlinks10_loop => \@output };
}

This is in the template:

<%Lastlinks10%>
<%loop Lastlinks10_loop%>
<b>&#183;&nbsp;</b><a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><b><%Title%></b></a>
<%if Description%>
<%Description%>
<%endif%>
<font face="verdana,arial" size="1" color="#cccccc">(Added: <%Add_Date%>)</font><br>
<%endloop%>

I guess what I am asking is how can I have the same output in the random links global as there is in the lastlinks? I have tried without luck. Any help would be greatly appreciated.

Thanks,

Jay

Last edited by:

LGJ31: Jan 23, 2002, 6:12 PM
Quote Reply
Re: [LGJ31] Changing output in random links global In reply to
Just change this line:

$output .= Links::SiteHTML::display ('link', $link);

to $output .= Links::SiteHTML::display ('new_link', $link);

and then create a new template called new_link.html and put your Title, Description or whatever variables you want to be displayed. I have about 5 different link formats set up this way and it works great.

Bryan
Quote Reply
Re: [BryanL] Changing output in random links global In reply to
Thanks very much Bryan. You're right, it works great.

Jay
Quote Reply
Re: [LGJ31] Changing output in random links global In reply to
Hi, how can I show the category a random link belongs to instead of the "Add_Date" using this global?

I tried changing:
<font face="verdana,arial" size="1" color="#cccccc">(Added: <%Add_Date%>)</font><br>

to:
<font face="verdana,arial" size="1" color="#cccccc">(Category: <%category%>)</font><br>

but it won't work.

Please advise. Thank you.

Quote Reply
Re: [Bruha] Changing output in random links global In reply to
Try:

get_cat_links


Code:
sub {
require Links::Build;
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
$catlink->select_options ('ORDER BY Full_Name ASC');
my @names = $catlink->select ({ LinkID => $id }, ['Full_Name'])->fetchall_list;
my @link_cats;
for (@names) {
push @link_cats, { cat_name => Links::Build::build ('title_unlinked',$_), cat_url => $cat_db->as_url($_)};
}
return { link_cats => \@link_cats };
}

</not a clue>
Quote Reply
Re: [Dinky] Changing output in random links global In reply to
Thanks Dinky but I am using the following global:

sub {
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY RAND()', 'LIMIT 15');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
$link->{Description};
push (@output, $link);
}
return { Random_Loop => \@output };
}

and the following in my link.html template:

<%link_random%>
<%loop Random_Loop%>
<b>&#183;&nbsp;</b><a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><b><%Title%></b></a>
<%if Description%>
<br><%Description%>
<%endif%>
<br><br>
<%endloop%>

It's working fine showing random links including description, but I want to add below the description the category a particular random link belongs to like:

Link Title
Link Description
Category> Subcategory

What do I need to add/change in the global above?

Quote Reply
Re: [Bruha] Changing output in random links global In reply to
You should be able to just add <%get_cat_links%> to your link.html file, will try it out when I get back to my computer tonight...

</not a clue>
Quote Reply
Re: [Dinky] Changing output in random links global In reply to
I'm getting an "unknown_tag" error using <%get_cat_links%>
Quote Reply
Re: [Bruha] Changing output in random links global In reply to
Did you go to Links Admin > Build > Template Globals and add the above code into as a global? and save as get_cat_links ??

Then pull it up with <%get_cat_links%>
???

</not a clue>
Quote Reply
Re: [Dinky] Changing output in random links global In reply to
it does not show anything and no errors either.

global name : get_cat_links

sub {
require Links::Build;
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
$catlink->select_options ('ORDER BY Full_Name ASC');
my @names = $catlink->select ({ LinkID => $id }, ['Full_Name'])->fetchall_list;
my @link_cats;
for (@names) {
push @link_cats, { cat_name => Links::Build::build ('title_unlinked',$_), cat_url => $cat_db->as_url($_)};
}
return { link_cats => \@link_cats };
}

I placed <%get_cat_links%> in home.html template to test it, built all, but nothing shows.

The previous one works for me except it does not show the categories.