Gossamer Forum
Quote Reply
Get a link's category id
How do i get a link's category id?

I want to be able to create a hyperlink to each link's category. Is there a tag that i can use to do this in link.html?
Quote Reply
Re: [Gregorio] Get a link's category id In reply to
Nope.

Not unless you have 1-link in 1-category only setup. There's no real way for a "link" to know what category it's in. Even in browsing, the relationship is lost on the detail pages (just for that reason, actually).

If you want to know what category a link is in, and you do have a 1:1 relationship, you just select the CategoryID from the CatLinks table, using the LinkID.

sub {
my $id = shift;
my $catlink = $DB->table('CatLinks','Category');
return ( $catlink->select ('Name', { LinkID => $id }) );
}


If you have links in related categories... you are pretty out of luck, as returns will be random (the first category a link was added to, and not deleted from).


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Get a link's category id In reply to
Quote:
There's no real way for a "link" to know what category it's in.

There is...you just showed how with your global :)

A link knows what category it is in by selecting from the CatLinks table.
Quote Reply
Re: [Paul] Get a link's category id In reply to
Not quite.

The problem is when browsing, if a link is in more than one category, there is no way to know what category you came from.

If you have a 1:1 relationship, you can make a good "guess" by selecting from the CatLinks table. Otherwise, you can either get a "list" of categories, or the first one. But, it's only a "guess".

On the other hand, a category _always_ knows what links it has in it, by selecting from the CatLinks table.

It's a not-so-subtle difference, especially if you are trying to code location code, or get a category name/path on the detail pages.

The only way would be if one of the "dynamic preserve" parameters was a category ID (ie: last category visited), that was reset when a new category was entered. You could then call the name or path of that category by using that parameter.

Because of this, GT would have to make some fundamental changes to the user code, and probably a bunch of other routines (and templates) (debugging) to pass c=CatID from page to page. This would work for dynamic sites, but _not_ static ones.

Yogi's page builder might be a solution, if it builds a detail page for each page in each category it's in, since tags would be different on each static page.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.