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
Quote Reply
Re: [DogTags] Random Loop and Related Links Loop - reduced html In reply to
Ok,

I will freely admit I have not looked at the whole message, and I have very little time, and very poor frame of mind, but -- here are some suggestions:


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


That line sends the link.html template to the display routine. "link" (without the .html) means use that template. _ALSO_ it means, to use a special subroutine called "link" to process the information, so that certain tags in the link (days_old, is_new, etc) are set properly.

You can change the display by using a different template, but you will need to create a new subroutine in the SiteHTML file, such as link_short, and then use a template called link_short.html.

When this is sent to the SiteHTML::display routine, it will see if a routine called "link_short" exists (you should make this just a copy of the link subroutine). If it does, control will be passed there, and the "link" will be processed correctly.

You want to change references to 'link' to 'link_short'.

You might have some other tweaks, but I can't say for sure. You could do this with additional globals, and such, but the globals would have to be essentially a copy of the link subroutine from SiteHTML anyway.

This is because of the processing of the links fields like isNew, days_old, etc, which are _not_ processed for any other template, except for link.html

Make sense???? (I'm not sure I do <G>)




PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Random Loop and Related Links Loop - reduced html In reply to
Many thanks, pugdog.Smile

I'm gonna dig in right now and see how I make out.

Much appreciated.

DogTags
Quote Reply
Re: [pugdog] Random Loop and Related Links Loop - reduced html In reply to
I converted the random code to the following and it works great. I changed link to link_random in 3 places.

Code:
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_random = $db->select->fetchrow_hashref;
my $html = Links::SiteHTML::display('link_random', $link_random);
return $html;
}

I also copied and renamed sub site_html_link in SiteHTML to:

Code:
sub site_html_link_random {
# --------------------------------------------------------
# Format a single link.
#
BLAH...BLAH...BLAH

# Parse the template.
return Links::user_page ('link_random.html', $rec, $opts);
}

And, I also created a link template, called link_random.html.

The random link is now terrific!

However, I tried to do the same thing with the Related stuff, but the old link.html file still keeps showing up.

Code:
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_related = $link_db->get ($related) or next;
$output .= Links::SiteHTML::display('link_related', $link_related);
}
return $output;
}

I also copied the link sub in SiteHTML and renamed it for related:

Code:
sub site_html_link_related {
# --------------------------------------------------------
# Format a single link.
#
BLAH...BLAH...BLAH

# Parse the template.
return Links::user_page ('link_related.html', $rec, $opts);
}

I also created a link_related.html file.

Would anyone have any thoughts on this?

Many thanks.

DogTags

------------------------------------------
Quote Reply
Re: [DogTags] Random Loop and Related Links Loop - reduced html In reply to
Hey, wait, it's working okay and looks great.

The Related works as simply the <%display_related%> tag.

Thanks, pugdog!

DogTags

Last edited by:

DogTags: Oct 28, 2001, 10:05 AM
Quote Reply
Re: [DogTags] Random Loop and Related Links Loop - reduced html In reply to
how to show category name for each random link ?



Thanks
Quote Reply
Re: [courierb] Random Loop and Related Links Loop - reduced html In reply to
I also want to know how to include the category name for each random link.
Anyone please?


In Reply To:
how to show category name for each random link ?



Thanks