Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Related Categories List

Quote Reply
Related Categories List
I am interested in providing a list of categories in which the link is present in the database. Currently I have a list of categories, to which the link is located, generated and displayed. You can see can example of this here:

http://www.policy.ca/...ry/Detailed/833.html

look down and at the "Subjects / Category:" field in the table. I like the way this works, but I would like to refine the result so that it presents that output like this,

Policy Articles / Aboriginal
Policy Articles / Aboriginal / Governance
Policy Articles / Aboriginal / Governance / 2003
Policy Articles / Aboriginal / Treaty Rights
Policy Articles / Aboriginal / Treaty Rights / 2003

This is the template global that I am currently using:

----------------------code------------------------

sub {
my $tags = shift;
my $seen;
my $id = $tags->{'ID'};
my $db = $DB->table ('Category','CatLinks');
my $sth = $db->select ( { LinkID => $id }, ['Name','Full_Name'] );
my $cat;
while (my ($name,$full_name) = $sth->fetchrow_array) {
if ($seen->{$name}) { next; }
$full_name =~ s/ /_/g;
$full_name =~ s/&/_/g;
$full_name =~ s/,/_/g;
$cat .= qq~<a href="$CFG->{build_root_url}/$full_name/index.html">$name</a><br>~;
$seen->{$name} = 1;
}
return $cat;
}

----------------------code------------------------

Any ideas on how i could change the Global Template to output like the example above? Is there already a template global or plugin that accomplishes this?

Quote Reply
Re: [mapleleafweb] Related Categories List In reply to
try this:

Code:

sub {
my $tag = shift;
my ($table, $sth, $catID, $cattable, $sth2, $name, @dirs, $output, $i);
$table = $DB->table ('CatLinks');
$sth = $table->select ( { LinkID => $tag->{ID} }, ['CategoryID'] );
$catID = $sth->fetchrow();
$cattable = $DB->table('Category');
$sth2 = $cattable->select ( { ID => $catID }, ['Full_Name'] );
$name = $sth2->fetchrow_array;
@dirs = split (/\//, $name);
$i = 0;
for (0 .. $#dirs) {
my $path = "/" . $cattable->as_url( join "/", @dirs[0 .. $_] );
$output .= " <a href=\"$CFG->{'build_root_url'}$path/$CFG->{'build_index'}\">$dirs[$_]</a>";
$output .= " /" if $i < $#dirs;
$i++;
}
return $output;
}


I think this is what you want...

- Jonathan
Quote Reply
Re: [jdgamble] Related Categories List In reply to
Yes, we're very close.

I replaced the original template global with your code and you can see the changes here:

http://www.policy.ca/...ailed%2F833.html;d=1

As you can see, the output was,

Policy Articles / Aboriginal / Governance

Which is very very close. However, the link is in more than that one category - as you can see from my top post.

Any ideas on how we could expand the output to include all the categories that link is present in?

Thanks!
Quote Reply
Re: [mapleleafweb] Related Categories List In reply to
Why not just change your original code to use the full name as the link name instead of $name?

Adrian
Quote Reply
Re: [mapleleafweb] Related Categories List In reply to
In Reply To:
Why not just change your original code to use the full name as the link name instead of $name?[/quote]
Because then it would not be linked the correct way. I know I'm O.C.D.

Try this:

Code:

sub {
my $tags = shift;
my $db = $DB->table ('Category','CatLinks');
my $cattable = $DB->table('Category');
my $sth = $db->select ( { LinkID => $tags->{'ID'} }, ['Name','Full_Name'] );
my $cat;
while (my ($name, $full_name) = $sth->fetchrow_array) {
my @dirs = split (/\//, $full_name);
my $i = 0;
for (0 .. $#dirs) {
my $path = $cattable->as_url(join "/", @dirs[0 .. $_]);
$cat .= qq~<a href="$CFG->{build_root_url}/$path/$CFG->{'build_index'}">$dirs[$_]</a>~;
$cat .= " / " if $i < $#dirs;
$i++;
}
}
return $cat;
}

hopefully getting closer...

- Jonathan
Quote Reply
Re: [jdgamble] Related Categories List In reply to
Excellent, this is great!

You can see the result here:
http://www.policy.ca/...ailed%2F833.html;d=1

The only things is, we need to have a <br /> in there to place a space between the different categories. I've tried placing <br /> in a few places, but can't seem to find the right place.
Quote Reply
Re: [mapleleafweb] Related Categories List In reply to
uh after this...

Code:

$i++;
}

add $cat . = "<br>\n";

Hopefully that should do it.

- Jonathan
Quote Reply
Re: [jdgamble] Related Categories List In reply to
Nope, I can't seem to get it to work

Here is the code in full with the <br> bolded:

Code:
sub {
my $tags = shift;
my $db = $DB->table ('Category','CatLinks');
my $cattable = $DB->table('Category');
my $sth = $db->select ( { LinkID => $tags->{'ID'} }, ['Name','Full_Name'] );
my $cat;
while (my ($name, $full_name) = $sth->fetchrow_array) {
my @dirs = split (/\//, $full_name);
my $i = 0;
for (0 .. $#dirs) {
my $path = $cattable->as_url(join "/", @dirs[0 .. $_]);
$cat .= qq~<a href="$CFG->{build_root_url}/$path/$CFG->{'build_index'}">$dirs[$_]</a>~;
$cat .= " / " if $i < $#dirs;
$i++;
add $cat . = "<br>\n";
}
}
return $cat;
}
Quote Reply
Re: [mapleleafweb] Related Categories List In reply to
Code:
sub {
my $tags = shift;
my $db = $DB->table ('Category','CatLinks');
my $cattable = $DB->table('Category');
my $sth = $db->select ( { LinkID => $tags->{'ID'} }, ['Name','Full_Name'] );
my $cat;
while (my ($name, $full_name) = $sth->fetchrow_array) {
my @dirs = split (/\//, $full_name);
my $i = 0;
for (0 .. $#dirs) {
my $path = $cattable->as_url(join "/", @dirs[0 .. $_]);
$cat .= qq~<a href="$CFG->{build_root_url}/$path/$CFG->{'build_index'}">$dirs[$_]</a>~;
$cat .= " / " if $i < $#dirs;
$i++;
}
$cat .= "<br>\n";
}
return $cat;
}



Sorry, thats what I meant. (I hate the way cut and paste works in this forum.)

Good luck!

- Jonathan
Quote Reply
Re: [jdgamble] Related Categories List In reply to
Perfect,

thanks for your help, Jonathan!
Quote Reply
Re: [mapleleafweb] Related Categories List In reply to
your welcome Wink

- Jonathan
Quote Reply
Re: [jdgamble] Related Categories List In reply to
Is their any way to order the output of the global to look more organized? For example, you see the output for the global above (for the same example used above) here: http://www.policy.ca/...ailed%2F833.html;d=1

Policy Articles / Aboriginal
Policy Articles / Aboriginal / Treaty Rights / 2003
Policy Articles / Aboriginal / Governance / 2003
Policy Articles / Aboriginal / Treaty Rights
Policy Articles / Aboriginal / Governance

However, I'd like it to be,

Policy Articles / Aboriginal
Policy Articles / Aboriginal / Governance
Policy Articles / Aboriginal / Governance / 2003
Policy Articles / Aboriginal / Treaty Rights
Policy Articles / Aboriginal / Treaty Rights / 2003

Any ideas?