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

Random Loop and Related Links Loop - reduced html

Quote Reply
Random Loop and Related Links Loop - reduced html
Hi All

I am using Random Links and Related Links.

The problem that I've been struggling with is that for each type, the entire link.html shows up when all I want to display are a few fields like titles, detail urls, brief descrips, image, etc.

I created a loop for each one and included tags, but they don't seem to work. Here is what I have for the subs and loops:

#############
RELATED SUB
#############
sub {
my $tags = shift;
my @related = split /\s*,\s*/, $tags->{RelatedLinks};
return if (! @related);
my $output = '';
my $link_db = $DB->table('Links');
foreach my $related (@related) {
my $link = $link_db->get ($related) or next;
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}

##############
RELATED LOOP
##############
<!--BEGIN display_related LOOP-->
<%display_related%>
<%loop display_related_loop%>
<b><u>Display Related</u></b><BR>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Item_Image%>&nbsp;&nbsp;<b><%Title%></b></a><BR>
<%endloop%>
<!--END display_related LOOP-->


#############
RANDOM SUB
#############
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;
}

##############
RANDOM LOOP
##############

<!--BEGIN random_link LOOP-->
Random Item:
<%random_link%>
<%loop random_link_loop%>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><b><%Title%></b></a><br>
<%Category%><br>
<%endloop%>
<!--END random_link LOOP-->

Would anyone know how to modify the subs to allow just the tags that I want to display through the loops? Thanks for your help.

Also, to limit the length of the Description in the Random and Related links, there is some neat code found in the topx (or top5 ?) hack. Can this Descrip limiting code be added to the adjusted Random and Related subs? I'm still struggling with Links SQL, getting the hang of everything. Here is the topx sub with the limited Descrip. It works great:

########
topx sub
########
sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC');
my $sth = $link_db->select;
###################
# my $output = ''; ## ORIGINAL
# while (my $link = $sth->fetchrow_hashref) { ## ORIGINAL
# $output .= Links::SiteHTML::display('link', $link); ## ORIGINAL
# } ## ORIGINAL
# return $output; ## ORIGINAL
##################
##################
my @output;
while (my $link = $sth->fetchrow_hashref) {
$link->{Description} =~ s/^(\w+\s\w+\s\w+\s\w+\s\w+).*$/$1.../;
push (@output, $link);
}
return { topx_loop => \@output };
#################
}

Sorry for such a long note. Many thanks for all of your help. I very much appreciate it. Smile Smile

DogTags

Last edited by:

DogTags: Oct 28, 2001, 4:48 AM
Subject Author Views Date
Thread Random Loop and Related Links Loop - reduced html DogTags 5090 Oct 28, 2001, 4:47 AM
Thread Re: [DogTags] Random Loop and Related Links Loop - reduced html
pugdog 4966 Oct 28, 2001, 6:24 AM
Post Re: [pugdog] Random Loop and Related Links Loop - reduced html
DogTags 4929 Oct 28, 2001, 7:29 AM
Thread Re: [pugdog] Random Loop and Related Links Loop - reduced html
DogTags 4926 Oct 28, 2001, 9:24 AM
Thread Re: [DogTags] Random Loop and Related Links Loop - reduced html
DogTags 4951 Oct 28, 2001, 10:03 AM
Thread Re: [DogTags] Random Loop and Related Links Loop - reduced html
courierb 4668 Aug 26, 2002, 9:57 PM
Post Re: [courierb] Random Loop and Related Links Loop - reduced html
Bruha 3787 Nov 19, 2006, 1:59 PM