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

Globals:: Last 5 and Last x by cateory

Quote Reply
Globals:: Last 5 and Last x by cateory
Hi All-

I have two globals that are for posting the last 5 links and also the last # by category.

I have recently changed my format to allow for non-website listings to appear on the detail page. Problem is now the globals only want to jump to a link and they can't differentiate between the links and non-links listings. Here are the globals, the last 5 I believe Andy gave to me. How can I make them work for both?

Last 5

sub {
my $LinkOwner = shift;
my $sth;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY ID DESC', 'LIMIT 5');
if ($LinkOwner) { $sth = $link_db->select( { isValidated => "Yes", LinkOwner => $LinkOwner } );
} else {
$sth = $link_db->select( { isValidated => "Yes" } );
}
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}



last by category

sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $cat = shift;
my $search_db = $DB->table('CatLinks', 'Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 3');
$sth = $search_db->select ( { isValidated => 'Yes', CategoryID => $cat });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('newestlink', $link);
}
return $output;
}



Could I also get one for Cool links?

Thanks!!

Last edited by:

SSmeredith: Oct 8, 2004, 8:07 AM
Quote Reply
Re: [SSmeredith] Globals:: Last 5 and Last x by cateory In reply to
Hi All-
I hope you were able to use these - is there any help for me with the problem I mentioned above?

Thanks!
M
Quote Reply
Re: [SSmeredith] Globals:: Last 5 and Last x by cateory In reply to
Can you have another go at explaining the problem that you want solving as it is not clear to me yet.
Quote Reply
Re: [afinlr] Globals:: Last 5 and Last x by cateory In reply to
    
Gee, it all seems so clear in my head Crazy

I have it set up as a link to a site or a link only to a detail page. So when I use the global, if one newest link is a real link it works as intended but if one of the last posts is a link to the detail page only, then I get a not found error.

Hope that helps...

Last edited by:

SSmeredith: Oct 14, 2004, 1:09 PM
Quote Reply
Re: [SSmeredith] Globals:: Last 5 and Last x by cateory In reply to
But both of these have entries in the links table? So this line:

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

shows the newestlink.html template. From what I understand you just need to change this template so that it has something like

<%if detaillink%>..detail link...<%else%> ..jump link..<%endif%> for the link (obviously this will depend on how you distinguish between the two types of links).

Or maybe I'm still not understanding?

Last edited by:

afinlr: Oct 14, 2004, 2:32 PM
Quote Reply
Re: [afinlr] Globals:: Last 5 and Last x by cateory In reply to
ok, I'm now giving myself big mental slap here.

Thanks!!
M
Quote Reply
Re: [SSmeredith] Globals:: Last 5 and Last x by cateory In reply to
Tongue
As for the cool links, something like this (this just shows the most popular - you could limit this futher by adding isPopular => 'Yes' to the select statement):

sub {
# Displays the coolest links on the home page.
my ($output,$sth,$link);
my $cat = shift;
my $search_db = $DB->table('CatLinks', 'Links');
$search_db->select_options ('ORDER BY Hits DESC Limit 3');
$sth = $search_db->select ( { isValidated => 'Yes', CategoryID => $cat });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}
Quote Reply
Re: [afinlr] Globals:: Last 5 and Last x by cateory In reply to
 I named the global 'cool' then added the tag <%cool%> but nothing appeared...?
I'll keep trying
Quote Reply
Re: [SSmeredith] Globals:: Last 5 and Last x by cateory In reply to
You'll need <%cool($ID)%> if you're using it on a Category page, or <%cool('7')%> with the number of the category that you want to show the links for on another page.
Quote Reply
Re: [afinlr] Globals:: Last 5 and Last x by cateory In reply to
Hello Afnir,

I would like to know if it is possible to use your Global with a loop?

I am not able to convert it.

Thank you for your assistance.

Oyo
Quote Reply
Re: [Oyo] Globals:: Last 5 and Last x by cateory In reply to
I think this should work

sub {
# Displays the coolest links on the home page.
my (@links,$sth,$link);
my $cat = shift;
my $search_db = $DB->table('CatLinks', 'Links');
$search_db->select_options ('ORDER BY Hits DESC Limit 3');
$sth = $search_db->select ( { isValidated => 'Yes', CategoryID => $cat });
while ($link = $sth->fetchrow_hashref) {
push @links, $link;
}
return {LinksLoop=>\@output};
}