Gossamer Forum
Quote Reply
Cats of a Links
I am not shure if i have solved this before.
I want to show something like:

This is a link
(saved in: Cars, Pets, Colors)

While i anyway use a global to pass the last five new links to the category page, i will try to fetch the cats also from catlinks/category.

But how i will do it at the normal category pages?
Quote Reply
Re: [Robert] Cats of a Links In reply to
Hi,

Not tested, but give this a go:

get_cats_for_link
Code:
sub {
my $LinkID = $_[0];
my $sth $DB->table("CatLinks")->select( ['CategoryID'], { LinkID => $LinkID });
my (@cat_ids,@cats);
while (my $cat_id = $sth->fetchrow) {
push @cat_ids, $cat_id
}

my $Category = $DB->table("Category");
$Category->select_options("ORDER BY Name DESC");
my $sth_cats = $Category->select( GT::SQL::Condition->new('ID','IN',\@cat_ids) );
while (my $cat = $sth_cats->fetchrow_hashref) {
$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};
push @cats, $cat;
}

return { cats_in_loop => \@cats }
}

Then call with:

Code:
<%get_cats_for_link($ID)%>
<%loop cats_in_loop%>
<a href="<%URL%>"><%Name%></a> <%if not last%>,<%endif%>
<%endloop%>

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] Cats of a Links In reply to
Small error there: You missed an = in the code. This works for me:

Code:
sub {
my $LinkID = $_[0];
my $sth = $DB->table("CatLinks")->select( ['CategoryID'], { LinkID => $LinkID });
my (@cat_ids,@cats);
while (my $cat_id = $sth->fetchrow) {
push @cat_ids, $cat_id
}

my $Category = $DB->table("Category");
$Category->select_options("ORDER BY Name DESC");
my $sth_cats = $Category->select( GT::SQL::Condition->new('ID','IN',\@cat_ids) );
while (my $cat = $sth_cats->fetchrow_hashref) {
$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};
push @cats, $cat;
}

return { cats_in_loop => \@cats }
}
Quote Reply
Re: [gotze] Cats of a Links In reply to
Where are you seeing the missing = ? Not sure I see it (could be from the lack of sleeping while camping ;))

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] Cats of a Links In reply to
Line 3 in your code. I inserted the missing = in my copy, highlighted with red.
Quote Reply
Re: [gotze] Cats of a Links In reply to
Oh yeah :)

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!