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

related categories global -> template

Quote Reply
related categories global -> template
Although I'm pretty sure this has been done before, I figured I would post my code in case someone needs it...

Code:

sub {
my $in = shift;
my $category = $in->{related};
my ($rec, $related);
my $cat = $DB->table('Category');
while ($category =~ m#<li><a href="([^"]+)">([^<]+)</a></li>#sog) {
$rec->{URL} = $1;
$rec->{Category} = $2;
$rec->{Number_of_Links} = $cat->select ( { Full_Name => $rec->{Category} }, ['Number_of_Links'] )->fetchrow();
$rec->{Category} =~ s,/, &gt ,g;
$related .= Links::SiteHTML::display('related_category', $rec);
}
return $related;
}

This allows you to put your related categories in a template using:

<%URL%>, <%Category%>, and <%Number_of_Links%>

related_category.html is your template...

Note: You obviously also have to call your global in your category.html template with whatever name your please Ex. <%new_related%>

Hope this helps someone...

- Jonathan
Quote Reply
Re: [jdgamble] related categories global -> template In reply to
Also, to count the number of related categories...
Code:
sub {
my $in = shift;
my $category = $in->{related};
my $count=0;
while ($category =~ m#<li>#sog) {
$count++;
}
return $count;
}


Peace...

- Jonathan