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

Display Links by Category on home.html

Quote Reply
Display Links by Category on home.html
Heya all,

I'm looking for a mod similar to the Yahoo Subcats plugin, except I don't want to show the sub-categories for a category, I'd like to display the Link titles of all links in that category (and subcats) ie: An output similar to this:

Category 1
- Link 1
- Link 2

Category 2
- Link 3
- Link 4

I've search and couldn't find this. Apologies in advance if I missed it.

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Display Links by Category on home.html In reply to
Hi,

Totally untested (and written with a hangover =)), but you could give this a go:

Code:
sub {

my $ctbl = $DB->table('Category');
$ctbl->select_options('ORDER BY Name ASC');
my $sth = $ctbl->select( { FatherID => 0 } ) || die $GT::SQL::error;
my @cats;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{links} = load_links($hit->{ID});
push @cats, $hit;
}

return { cat_loop => \@cats };

sub load_links {

my $tbl = $DB->table('CatLinks','Links');
$tbl->Select_options('LIMIT 20','ORDER BY Title ASC');
my $sth = $tbl->select( GT::SQL::Condition->new('CatLinks.CategoryID','=',$_[0]) ) || die $GT::SQL::error;
my $back;
while (my $hit = $sth->fetchrow_hashref) {
$back .= qq|<a href="#">$hit->{Title}</a>|<br />|;
}
return $back;
}

}

Call with:

Code:
<%global_name%>

..and then:
Code:
<%loop cat_loop%>
NORMAL CATEGORY STUFF
<%links%> <%-- this will show the link titles for this cat --%>
<%endloop%>

Hope that helps =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display Links by Category on home.html In reply to
Hey Andy!

Hope you're doing well. Smile Thanks for having a go at this. I get:

Code:
Unable to compile 'catlinks': syntax error at (eval 2944) line 21, near "/>"

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Display Links by Category on home.html In reply to
Hi,

Ya, not doing too bad thanks =)

Regarding the error, that serves me right trying to write this global when recovering from a hangover Tongue

The line:

Code:
$back .= qq|<a href="#">$hit->{Title}</a>|<br />|;

..should read:

Code:
$back .= qq|<a href="#">$hit->{Title}</a> <br />|;

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!