Gossamer Forum
Quote Reply
Show Cat Names In MOD
Hi,
So I implemented the show subcatlinks mod where I want to show all subcategory links on the category page.
Works great, thanks.

But, they show up all together. Is there a way to show something like this:

Category
link
link

Subcat name or desc
link
link

Other Subcat Name or desc
link
link

Doesnt have to get the name straight as subcat name, I can hard code it since all categories contain the same subcategories.

Current code Im using is:

sub {
my $output;
my $tags = shift;
return '' unless ($tags->{ShowSubCategoryLinks});
my $cat_id = $tags->{ID};
my $subcats = $DB->table('Category')->children($cat_id);
push @$subcats, $cat_id;
my $link_db = $DB->table('Links','CatLinks');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $subcats);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}


So with this code all links in all subcats show up without showing which subcat they belong to.
Any help would be apreciated.
Juan Carlos Gorospe
Quote Reply
Re: [Gorospe] Show Cat Names In MOD In reply to
I think this is a relevant post:
http://www.gossamer-threads.com/...i?post=222918#222918
Quote Reply
Re: [afinlr] Show Cat Names In MOD In reply to
Hi,
Thanks for your reply.
This is the code as I entered it in globals:

sub {
my $tags = shift;
my $cat_id = $tags->{'ID'};
my $name = $tags->{'Name'};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ("ORDER BY Title ASC");
my $sth = $link_db->select ( { CategoryID => $cat_id, isValidated => 'Yes' });
my $output = qq~ <b>$name:</b><br> ~;
while (my $link = $sth->fetchrow_hashref) {
$output .= qq~ <li>$link->{'Title'} ~;
}
my $cat_db = $DB->table('Category');
my $sth2 = $cat_db->select ( ['ID','Name'],{ FatherID => $cat_id });
while (my ($child_id,$subname) = $sth2->fetchrow_array){
$output .= qq~ <br><br><b>$subname:</b><br> ~;
$link_db->select_options ("ORDER BY Title ASC");
my $sth3 = $link_db->select ( { CategoryID => $child_id, isValidated => 'Yes' });
while (my $link2 = $sth3->fetchrow_hashref) {
$output .= qq~ <li>$link2->{'Title'} ~;
}
}
return $output;
}

Works great. But its not linking the title with the url associated with it and its not displaying the description. Ive tweaked it to the best of my knowledge, but I only get errors...
Any ideas?

Thank you
Quote Reply
Re: [Gorospe] Show Cat Names In MOD In reply to
You can just use the link.html template like this:

sub {
my $tags = shift;
my $cat_id = $tags->{'ID'};
my $name = $tags->{'Name'};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ("ORDER BY Title ASC");
my $sth = $link_db->select ( { CategoryID => $cat_id, isValidated => 'Yes' });
my $output = qq~ <b>$name:</b><br> ~;
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
my $cat_db = $DB->table('Category');
my $sth2 = $cat_db->select ( ['ID','Name'],{ FatherID => $cat_id });
while (my ($child_id,$subname) = $sth2->fetchrow_array){
$output .= qq~ <br><br><b>$subname:</b><br> ~;
$link_db->select_options ("ORDER BY Title ASC");
my $sth3 = $link_db->select ( { CategoryID => $child_id, isValidated => 'Yes' });
while (my $link2 = $sth3->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link2);
}
}
return $output;
}
Quote Reply
Re: [afinlr] Show Cat Names In MOD In reply to
Worked great. Thank you very much.