Gossamer Forum
Home : Products : Gossamer Links : Discussions :

categoryID in link.html template

Quote Reply
categoryID in link.html template
hello,

Does anybody now how to get the proper category ID in the link.html template???
I need this for a modification.

Quote Reply
Re: categoryID in link.html template In reply to
ridesworld

What exactly do you want it to output?

An example would be great!



http://www.sfahq.com
Phil the FOG
Quote Reply
Re: categoryID in link.html template In reply to
simply with the categoryID (in which a link is), you can submit it in the database for a badlink, review report, and you couls give editors rights to modify/delete reports.




Quote Reply
Re: categoryID in link.html template In reply to
This is what I did.

In template globals I added a global called link_category_id with this code.
sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table ('Category','CatLinks');
my $sth = $db->select ( { 'CatLinks.LinkID' => $id }, ['Category.ID', 'Category.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 = $id;
}


}
return $cat;
}

it's crude, but it works. I hope it helps. If anyone has a better solution, I too would love to hear it.

peace.

Quote Reply
Re: categoryID in link.html template In reply to
klangan,

your code works like a charm - i wanted to display the actual category-name of a link in the detailed-template, so i changed $cat = $id; with $cat = $name ... any idea how to display the whole thing including a main- and sub-categories?

Thanks.


Quote Reply
Re: categoryID in link.html template In reply to
without seeing an example of what you mean I'm not sure.

If you're trying to get the Full_Name of the category, then replace "Category.Name" with "Category.Full_Name" in the select statement, otherwise you'll need to be more specific as to what you want. Give an example if you can.

peace.

Kyle

Quote Reply
Re: categoryID in link.html template In reply to
Hi Kyle,

thanks again - that's what i wanted!


Quote Reply
Re: [klangan] categoryID in link.html template In reply to
Hi Kyle,

Cool that's a thing I long wanted to achieve. Thank you!

One question:
I display this as a list of categories on the detailed page to show in which categories the link resides. How can I display them as links to the according categories so that users can jump directly to this or that category if they wish?

Here is what I've made of your global so far:

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 = "<ul>";
while (my ($id,$name) = $sth->fetchrow_array) {
$cat .= "<li>".$name ."</li>";
}
$cat .= "</ul>";
return $cat;
}

(This way you avoid the extra comma at the end of the list.)

Displays a list like
  • Countries/Europe/Germany
  • Institutions/Research Centres/Prehistory
  • Museums & Exhibitions/Germany


That's great so far, just that I'd like to make the list items clickable for users ... but how?
Wink

Andreas
-------------------------------------------------
http://www.archaeologie-online.de
Quote Reply
Re: [Digger] categoryID in link.html template In reply to
If all you want to do is make those names clickable, there have been several suggestions in recent weeks:

Code:


my ($cat_id, $cat_name) = %{$LINKDB->get_categories ($link->{'ID'})}; ## Returns the category name & ID from link ID
$link->{'title_linked'} = Links::Build::build ('title_linked', "$cat_name/$link->{Title}");
## Fix up the HTML references
my ($begin, $url, $output); ## setting up for a very, very complicated regex, taken from Links.pm clean_output
$link->{'title_linked'} =~ s!(<a[^>]+href\s*=\s*["']*)$CFG->{build_root_url}/?([^"'>]*)!
($begin, $url) = ($1, $2);
$output = "$1$CFG->{db_cgi_url}/page.cgi?g=" . $IN->escape($2);
$output;
!eisog;


From Build.pm, the current use seems to be:

Code:


Here's the call:

my $title = build ('title_linked', { name => $cat, complete => 1 });

And this is what it calls:

sub build_title_linked {
# ------------------------------------------------------------------
# Generate a linked title.
#
my $input = shift;
my $complete = 0;
my $home = 1;
if (ref $input) {
$complete = $input->{complete} || 0;
$home = defined $input->{home} ? $input->{home} : 1;
$input = $input->{name};
}
my (@dirs, $dir, $output, $path, $last, $db, $top);

$db = $DB->table('Category');
$top = Links::language('LINKS_TOP') || 'Top';

@dirs = split (/\//, $input);
$last = pop @dirs unless ($complete);
$output = $home ? qq| <a href="$CFG->{build_root_url}/$CFG->{build_index}">$top</a> :| : '';
for (0 .. $#dirs) {
$path = "/" . $db->as_url ( join "/", @dirs[0 .. $_] );
$output .= qq| <a href="$CFG->{build_root_url}$path/$CFG->{build_index}">$dirs[$_]</a> :|;
}
if ($complete) {
chop $output; chop $output;
}
else {
$output .= " $last";
}
return $output;
}


This should be a starting point :)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] categoryID in link.html template In reply to
Cool Hi Pugdog,

thanks a lot!
It works like a charm.

Here is the complete global for those who want to try it:

link_category_id =>
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 = "<ul>";
while (my ($id,$name) = $sth->fetchrow_array) {
my $title = Links::Build::build ('title_linked', { name => $name, complete => 1 });
$cat .= "<li>".$title."</li>";
}
$cat .= "</ul>";
return $cat;
}

Cheers,

Andreas
-------------------------------------------------
http://www.archaeologie-online.de
Quote Reply
Re: [Digger] categoryID in link.html template In reply to
How can I use this function on fav.cgi page. When I try it, it is giving me following error.

A fatal error has occured:

Undefined subroutine &Links::Build::build called at (eval 14) line 1.

Please enable debugging in setup for more details.

Vishal
-------------------------------------------------------
Quote Reply
Re: [TRPN] categoryID in link.html template In reply to
Try adding

use Links::Build;

at the beginning of the sub.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] categoryID in link.html template In reply to
Hate to be sounding stupid, but you mean?


sub { my ($rec) = @_;


Links::Build;


my $id = $rec->{ID};
my $db = $DB->table ('Category','CatLinks');
my $sth = $db->select ( { 'CatLinks.LinkID' => $id }, ['Category.ID', 'Category.Full_Name'] );
my $cat = "<ul>";
while (my ($id,$name) = $sth->fetchrow_array) { my $title = Links::Build::build ('title_linked', { name => $name, complete => 1 });
$cat .= "<li>".$title."</li>"; }
$cat .= "</ul>";
return $cat;
}

=========

Above is not working --- Frown

Vishal
-------------------------------------------------------

Last edited by:

TRPN: Jul 17, 2002, 11:32 PM
Quote Reply
Re: [TRPN] categoryID in link.html template In reply to
Almost!

sub { my ($rec) = @_;
use Links::Build;
my $id = $rec->{ID};

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] categoryID in link.html template In reply to
Great, this is working great.

I love it. Blush Blush Blush Blush

Vishal
-------------------------------------------------------

Last edited by:

TRPN: Jul 17, 2002, 11:38 PM
Quote Reply
Re: [yogi] categoryID in link.html template In reply to
Your should use require rather than use.
Post deleted by nt6 In reply to