Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Listing all the link's categories on the detailed page

Quote Reply
Listing all the link's categories on the detailed page
Is it possible to list all of the categories that a link is currently assigned to? I would like to be able to list all the different categories a link is assigned to on the detailed page of the links.

Cheers,

Greg
Quote Reply
Re: [mapleleafweb] Listing all the link's categories on the detailed page In reply to
Try this;

At the top of detailed.html, put: <%find_out_additional_cats($ID)%>

... and then create a new global, called find_out_additional_cats, with the following code;

Code:
sub {

my $ID = $_[0];
my $sth = $DB->table('CatLinks','Category')->select( { LinkID => $ID } ) || return $GT::SQL::error;
my @back;
while (my $hit = $sth->fetchrow_hashref) {
push @back, $hit;
}

return { additional_cats => \@back };

}

Then, in detailed.html you should be able to use;

Code:
<%if additional_cats%>
<%loop additional_cats%>
<%include subcategory.html%><BR>
<%endloop%>
<%endif%>

Hope that helps.

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] Listing all the link's categories on the detailed page In reply to
Hi Andy, I've been playing around with loops recently. I *think* you can get the same loop with this (because the loop will take either an arrayref or a hashref - which I've only just found out):

sub {
my $ID = $_[0];
my $back = $DB->table('CatLinks','Category')->select( { LinkID => $ID } )->fetchall_hashref || return $GT::SQL::error;
return { additional_cats => $back };
}
Quote Reply
Re: [Andy] Listing all the link's categories on the detailed page In reply to
When I try what you've suggested, I get this error,
Unknown Tag: 'Short_Name' (27)
Unknown Tag: 'Short_Name' (23)

Unknown Tag: 'Short_Name' (21)

Unknown Tag: 'Short_Name' (25)

Unknown Tag: 'Short_Name' (32)

Unknown Tag: 'Short_Name' (3)

Unknown Tag: 'Short_Name' (22)

Unknown Tag: 'Short_Name' (2)

Unknown Tag: 'Short_Name' (1)

Unknown Tag: 'Short_Name' (3)

Not sure what this means? Also, will this list of categories be linked to their appropriate space in the directory?

Thanks for all your helps guys,

Cheers,

Greg
Quote Reply
Re: [mapleleafweb] Listing all the link's categories on the detailed page In reply to
Is this question, perhaps, posted in the wrong forum? Should I have posted this in the Development, Plugins and Globals forum?

Cheers,

Greg
Quote Reply
Re: [mapleleafweb] Listing all the link's categories on the detailed page In reply to
Try this

sub {
my $tags = shift;
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) {
$full_name =~ s/ /_/g;
$cat .= qq~<a href="CFG->{build_root_url}/$full_name/index.html">$name</a><br>~;
}
return $cat;
}

and just put <%globalname%> in the template - where globalname is the name of your global.
Quote Reply
Re: [afinlr] Listing all the link's categories on the detailed page In reply to
Ok, you can see what I get here http://www.policy.ca/...ory/Detailed/22.html (scroll down till you see Policy Areas Covered: [?]

the links don't work, you can see that when I click on the first link, it tries to take me to,
http://www.policy.ca/...nstitutes/index.html

You can see that the organization, National Council of Welfare, covers these policy areas, Public Administration, Child and Familiy, Aboriginal, Welfare and Social Justice, Crime and Justice. This means that this organization has been placed in those categories in the directory. Is it possible to have it list the categories like his,


Public Administration
Child and Familiy
Aboriginal
Welfare and Social Justice
Crime and Justice

And have each listed category linked to the root category - like I've done above?

Sorry I wasn't more clear earlier.

Thanks again for the help

Greg
Quote Reply
Re: [mapleleafweb] Listing all the link's categories on the detailed page In reply to
I'm sure I just copied and pasted that from one of my old posts ... somehow I lost a $:

$cat .= qq~<a href="$CFG->{build_root_url}/$full_name/index.html">$name</a><br>~;

To do what you've asked now is more complicated. I think something like this may work:

sub {
my $tags = shift;
my $id = $tags->{'ID'};
my $db = $DB->table ('Category','CatLinks');
my $sth = $db->select ( { LinkID => $id }, ['Full_Name'] );
my $cat;
while (my ($full_name) = $sth->fetchrow_array) {
$full_name =~ s,^([^/]*)/.*$,$1,;
my $name=$full_name;
$full_name =~ s/ /_/g;
$cat .= qq~<a href="$CFG->{build_root_url}/$full_name/index.html">$name</a><br>~;
}
return $cat;
}
Quote Reply
Re: [afinlr] Listing all the link's categories on the detailed page In reply to
Brilliant! Bang on! That works prefect.

I really appreciate your help


Cheers,

Greg
Quote Reply
Re: [afinlr] Listing all the link's categories on the detailed page In reply to
Another question:

When using your technique to display and link to a links categories, I get a broken link if the Category name has a comma in it. For example, the following category has a comma, International Trade, Development and Finance. But the link is as follows, http://www.policy.ca/...d_Finance/index.html

But with the technique you've created, I get this as the link, http://www.policy.ca/...d_Finance/index.html

Which results in a broke link.

is there a way around this?
Quote Reply
Re: [mapleleafweb] Listing all the link's categories on the detailed page In reply to
Try this:

sub {
my $tags = shift;
my $id = $tags->{'ID'};
my $db = $DB->table ('Category','CatLinks');
my $sth = $db->select ( { LinkID => $id }, ['Full_Name'] );
my $cat;
while (my ($full_name) = $sth->fetchrow_array) {
$full_name =~ s,^([^/]*)/.*$,$1,;
my $name=$full_name;
my $url=$DB->table('Category')->as_url($full_name);
$cat .= qq~<a href="$CFG->{build_root_url}/$url/index.html">$name</a><br>~;
}
return $cat;
}
Quote Reply
Re: [afinlr] Listing all the link's categories on the detailed page In reply to
Yup, it worked.

Thanks again,

Cheers,

GReg