Gossamer Forum
Home : Products : Gossamer Links : Discussions :

display category path in link.html

Quote Reply
display category path in link.html
how can i display the path to the category under each link like google? thanks in advance!

Quote Reply
Re: display category path in link.html In reply to
this is a modification of
http://gossamer-threads.com/...NG&Number=147726
In template globals I added a global called link_category_id with this code:
Code:
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;
$cat = "<a href=$name>$name</a>";

}
return $cat;
}
you might have to change the ahref around to work properly for your installation of links. and put <%link_category_id%> wherever you want it to work. i put it in link.html but i did this, so it only is shown when someone is searching:
Code:
<%if query%>
<a class="category_links" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a>
Category: <%link_category_id%>
<%else%>
<a class="category_links" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a>
<%endif%>
Quote Reply
Re: [poil11] display category path in link.html In reply to
Hi:

The code doesn't work because:

Code:
$cat = "<a href=$name>$name</a>"

short like http://domain.com/cgi-bin/Category

For me this is not the correct path, but with this code:

Code:
$cat = "<a href=$CFG->{build_root_url}/$name>$name</a>";

Works fine!!!

Greetings!

-----------------------
Nomada
Quote Reply
Re: [poil11] display category path in link.html In reply to
Hello :-)

I really like this pretty global! But is there a way how modify it to show ALL categories in which the link is listed?

Thank you in ahead for any posts :-)

Robo
Quote Reply
Re: [Robo] display category path in link.html In reply to
I use the following global
Code:
sub {
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
my %names = $catlink->select ('LinkID', 'Full_Name', { LinkID => $id })->fetchall_list;

my @link_cats;
foreach (keys %names) {

push @link_cats, {cat_name => Links::Build::build ('title_unlinked', $names{$_}), cat_url => $cat_db->as_url($names{$_})};
}
return { link_cats => \@link_cats };
}
together with the following code in link.html
Code:
<%loop link_cats%>
<a href="<%cat_url%>" class="dimmed"><%cat_name%><br />
<%endloop%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Jul 25, 2002, 5:37 AM
Quote Reply
Re: [yogi] display category path in link.html In reply to
>>
return {link_cats} = \@link_cats };
<<

*cough* Smile
Quote Reply
Re: [Paul] display category path in link.html In reply to
did I hear something????

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] display category path in link.html In reply to
Yep, check the formatting :)
Quote Reply
Re: [yogi] display category path in link.html In reply to
Hello Yogi :-)

Thank you for the code! Anyway - it is not working :-( Let's see why:

1) I create global named "link_cats" and I put inside that global this code (which includes Paul's correction):

Code:


sub {
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
my %names = $catlink->select ('LinkID', 'Full_Name', { LinkID => $id })->fetchall_list;

my @link_cats;
foreach (keys %names) {

push @link_cats, {cat_name => Links::Build::build ('title_unlinked', $names{$_}), cat_url => $cat_db->as_url($names{$_})};
}
return {link_cats} = \@link_cats };
}


2) Then I put following code inside my detailed.html:

Code:


<%loop link_cats%>
<a href="<%cat_url%>"><%cat_name%><br>
<%endloop%>


3) And the result is NOTHING. It doesn't show anything in the final page, just blank space.

Any suggestions?

Robo
Quote Reply
Re: [Robo] display category path in link.html In reply to
First of all, what you call Paul's correction, is actually not a correction. Paul was citing the wrong code in my post, which I then corrected. My code should now be fine.

Second, you need to call you global something like "get_link_cats", not "link_cats", because that will be the name of the returned loop.

In your template you would then use:

<%get_link_cats($ID)%>
<%loop link_cats%>
<a href="<%cat_url%>"><%cat_name%><br />
<%endloop%>

This should work.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] display category path in link.html In reply to
Hello Yogi Tongue

Thank you for your concern! Anyway - it is still not working as it should - it is much more better now, because it show at least something, but it still shows ONLY the last (in ABC order) of the selected categories. I think we are almost there, only the last correction is needed Sly

Thank you very much for your help Smile

Robo

P.S. You have interesting homepage Wink
Quote Reply
Re: [Robo] display category path in link.html In reply to
You are right, it was actually only giving one category... and I haven't noticed it all the time....

Anyway, the follwoing works on my site, so it should also on yours,
Code:
sub {
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
my @names = $catlink->select ({ LinkID => $id }, ['Full_Name'])->fetchall_list;
my @link_cats;
for (@names) {
push @link_cats, { cat_name => Links::Build::build ('title_unlinked',$_), cat_url => $cat_db->as_url($_)};
}
return { link_cats => \@link_cats };
}
Of course I have an interesting homepage Cool

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Jul 26, 2002, 1:07 AM
Quote Reply
Re: [yogi] display category path in link.html In reply to
Thank you! It is working right now!! Cool

For all the others... The final code is:

1) Create global named get_link_cats and put inside:

Code:


sub {
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
my @names = $catlink->select ({ LinkID => $id }, ['Full_Name'])->fetchall_list;

my @link_cats;
for (@names) {

push @link_cats, { cat_name => Links::Build::build ('title_unlinked',$_), cat_url => $cat_db->as_url($_)};
}
return { link_cats => \@link_cats };
}


2) Then put this in your detailed template (or elsewhere):

Code:
<%get_link_cats($ID)%>
<%loop link_cats%>
<a href="http://www.yourdomain.com/yourpath/<%cat_url%>" target="_top"><%cat_name%></a><br>
<%endloop%>
And there you goo... Wink
Quote Reply
Re: [Robo] display category path in link.html In reply to
Thanks to Yogi, here is his "final final" code which:
  1. includes ABC order
  2. can be used on any page, including add and modify pages

Code:


sub {
require Links::Build;
my $id = shift;
my $cat_db = $DB->table('Category');
my $catlink = $DB->table('CatLinks','Category');
$catlink->select_options ('ORDER BY Full_Name ASC');
my @names = $catlink->select ({ LinkID => $id }, ['Full_Name'])->fetchall_list;

my @link_cats;
for (@names) {

push @link_cats, { cat_name => Links::Build::build ('title_unlinked',$_), cat_url => $cat_db->as_url($_)};
}
return { link_cats => \@link_cats };
}

Last edited by:

Robo: Jul 26, 2002, 6:37 AM
Quote Reply
Re: [Robo] display category path in link.html In reply to
In Reply To:
can be used on any page, including add and modify pages


I must be missing a tweak for the Home Page - no data
Quote Reply
Re: [Robo] display category path in link.html In reply to
I know this post is a long time ago but I ned help how to do this

display category path in link.html

Thanks