how can i display the path to the category under each link like google? thanks in advance!
Jul 24, 2001, 10:21 AM
Novice (41 posts)
Jul 24, 2001, 10:21 AM
Post #2 of 16
Views: 8849
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:
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:
<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%>
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;
}
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%>
Mar 19, 2002, 9:44 AM
User (144 posts)
Mar 19, 2002, 9:44 AM
Post #3 of 16
Views: 8632
Hi:
The code doesn't work because:
short like http://domain.com/cgi-bin/Category
For me this is not the correct path, but with this code:
Works fine!!!
Greetings!
-----------------------
Nomada
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
Jul 25, 2002, 5:29 AM
Veteran / Moderator (2199 posts)
Jul 25, 2002, 5:29 AM
Post #5 of 16
Views: 8483
I use the following global
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
<a href="<%cat_url%>" class="dimmed"><%cat_name%><br />
<%endloop%>
Ivan
-----
Iyengar Yoga Resources / GT Plugins
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 };
}
Code:
<%loop link_cats%> <a href="<%cat_url%>" class="dimmed"><%cat_name%><br />
<%endloop%>
Ivan
-----
Iyengar Yoga Resources / GT Plugins
Jul 25, 2002, 5:31 AM
Veteran / Moderator (2199 posts)
Jul 25, 2002, 5:31 AM
Post #7 of 16
Views: 8438
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):
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:
<%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
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
Jul 25, 2002, 1:27 PM
Veteran / Moderator (2199 posts)
Jul 25, 2002, 1:27 PM
Post #10 of 16
Views: 8539
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
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
Jul 26, 2002, 12:48 AM
User (86 posts)
Jul 26, 2002, 12:48 AM
Post #11 of 16
Views: 8478
Hello Yogi
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
Thank you very much for your help
Robo
P.S. You have interesting homepage

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

Thank you very much for your help

Robo
P.S. You have interesting homepage

Jul 26, 2002, 1:04 AM
Veteran / Moderator (2199 posts)
Jul 26, 2002, 1:04 AM
Post #12 of 16
Views: 8444
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,
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
Ivan
-----
Iyengar Yoga Resources / GT Plugins
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 };
}

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Jul 26, 2002, 2:13 AM
User (86 posts)
Jul 26, 2002, 2:13 AM
Post #13 of 16
Views: 8494
Thank you! It is working right now!!
For all the others... The final code is:
1) Create global named get_link_cats and put inside:
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):
<%loop link_cats%>
<a href="http://www.yourdomain.com/yourpath/<%cat_url%>" target="_top"><%cat_name%></a><br>
<%endloop%>And there you goo...

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%>

Jul 26, 2002, 6:24 AM
User (86 posts)
Jul 26, 2002, 6:24 AM
Post #14 of 16
Views: 8449
Thanks to Yogi, here is his "final final" code which:
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 };
}
- includes ABC order
- 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 };
}