Gossamer Forum
Home : Products : Gossamer Links : Discussions :

List categories under each link

Quote Reply
List categories under each link
I have "Links sql" version 2.0.5 and i am trying to display under each link that the search by keywords displays the category it belongs to underneith.

I am not interested in grouping the links by category in the keyword result page but I am in displaying after each link separately the category it belongs to.

Obviously i wouldnīt want this to happen in the links displayed by Category search.

I have looked trough previous posts but I only find the way of doing this for Links 2.0. (I have Links sql 2.05).

Any help on this issue is appreciated.

Thank you...

Quote Reply
Re: [Ross_Leo] List categories under each link In reply to

Hmm, you would need a global for this:

category_info =>
sub {
my $tags = shift;
my $id = $tags->{ID};
my $link_db = $DB->table('Links');
my %cats = $link_db->get_categories($id);
my ($cat_id, $cat_name) = each %cats;
return $cat_name;
So if you put: <%category_info%>, it will return the name of the category that link is in.


Gossamer Threads Inc.
Quote Reply
Re: [Alex] List categories under each link In reply to
Thanks for the code, but it doesnīt display anything in my search results.

You are probably thinking if i did it right. I created the category_info in template globals and added to link.html the tag <%category_info%>

It doesnīt give a tag error but it doesnīt show anything either.
I was using the correct template set as well.

Any ideas why?Smile
Quote Reply
Re: [Ross_Leo] List categories under each link In reply to
Sorry to reply to my own posts every 5 minutes but
I have just figured out the way round it at my style
Crazy (remember i am not a programmer so
please donīt laugh).

I have found 2 codes in the forum.

The first one i have modifed myself so it substitutes
the "&" and the "," with "_" . (to get the hyperlinks
right). This part of the code only acts as I hyperlink
to the correct category. In the a href I inserted the
word category so that the users donīt view the ugly
url with all of the "___" instead of the characters ","
and "&".

sub {
my ($rec) = @_;my $id = $rec->{ID};my $db = $DB-
>table ('Category','CatLinks');my $sth = $db->select
( { 'CatLinks.LinkID' => $id },
['Category.ID', 'Category.Full_Name'] );my
$cat;while (my ($id,$name) = $sth->fetchrow_array)

{$name =~ s/ /_/g;$name =~ s/&/_/g;$name =~
s/,/_/g;$cat = "<a href=http://www.ultracosta.com/
$name>Category:</a>";}return $cat;

The second one is the part that displays the text of
the category with no hyperlink. Just the name of the
category in a understandable way.

sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table ('Category','CatLinks');
my $sth = $db->select ( { 'CatLinks.LinkID' =>
$id }, ['Category.ID', 'Category.Full_Name'] );
my $cat;
while (my ($id,$name) = $sth->fetchrow_array) {

# the following if statements are only useful if you're
in dynamic mode.
# the g parameter is then passed in and if your link
is in multiple categories, it'll pull out the right one
# if you want a list of all the categories, then
remove the if statements and just leave $cat .=
$id .",";
# that should give you a list like 15,25,30, sorry
about the extra comma.

if ($rec->{g}) {
$name =~ s/ /_/g;
if ($rec->{g} =~ /$name/) {
$cat = $id;
} else {
$cat = $name ;

return $cat;

With the 2 pieces of code i have created to global
templates and inserted them into links.html.


Thanks for the help.Smile
Quote Reply
Re: [Ross_Leo] List categories under each link In reply to
Itīs me again.

Just one more thing.

In the links.html I have put the template globals tags under the <%if query%> tag. This way i donīt get the categories appearing under the links when somebody already is searching by category.

Great forum when you know what you are looking for !!!
Quote Reply
Re: [Ross_Leo] List categories under each link In reply to
I use the following code as a global successfully:




sub {
my $tag = shift;

my $table = $DB->table ('CatLinks');
my $sth = $table->select ( { LinkID => $tag->{ID} }, ['CategoryID'] );

my $catID = $sth->fetchrow();

my $cattable = $DB->table('Category');
my $sth2 = $cattable->select ( { ID => $catID }, ['Full_Name'] );

my $name = $sth2->fetchrow_array;
my $clean_name = $cattable->as_url($name);
my $url = "<a href=\"" . $CFG->{build_root_url} . "/" . $clean_name . '/' . $CFG->{build_index} . "\">" . $name . "</a>";

return $url;

Then in the link.html template I include:

<%if query%>

Make sure that in the Setup for Search Options you designate:


with "No" selected.

This should work fine.