Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Accessing Category Description in Detailed page

Quote Reply
Accessing Category Description in Detailed page
Hi, I want to access the category information in the detailed page template. The variable dump did not show any category information. Any tips on what I should be loading? Been searching around for an hour on terms like access category in detailed etc. Not found anything. :(
Quote Reply
Re: [shrirch] Accessing Category Description in Detailed page In reply to
Try this...

Create a new global called cat_details...

Code:
sub {

my $LinkID = $_[0];
my $CatID;

my $table = $DB->table('CatLinks');
my $sth = $table->select( { LinkID => $LinkID } ) || return $GT::SQL::error;

while (my $hit = $sth->fetchrow_hashref) {
$CatID = $hit->{CategoryID};
}

my $table = $DB->table('Category');
my $sth = $table->select( { ID => $CatID } ) || return $GT::SQL::error;

my @return_loop;
while (my $link = $sth->fetchrow_hashref) {
push (@return_loop, $link);
}

return { cat_details_loop => \@return_loop };

}

Call it at the top of your HTML template with;

Code:
<%cat_details($ID)%>

... then when you need to show the data, just use something like;

Code:
<%loop cat_details_loop%>
<%Title%> <BR>
<%ID%> <BR>
<%Description%> <BR>
... etc
<%endloop%>

Just tried it on my dev installation, and it works a charm Cool

Cheers

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] Accessing Category Description in Detailed page In reply to
Andy,

Thanks. Will try it out. Do have a question... why do I need the loop? Is that for cases when the link is copied into several categories?
Quote Reply
Re: [shrirch] Accessing Category Description in Detailed page In reply to
Nah, it just works out faster when trying to grab all the details, and also shorted for the global. Otherwise you would need stuff like;

$
Code:
Description = $hit->{Description};
$Title = $hit->{Title};
$ID = $hit->{ID};
$Image = $hit->{Image};

.. etc.

and then to return them, you would need;

return { cat_Description => $Description, cat_Title => $Title, cat_ID => $ID, cat_Image => $Image };


...etc.

As you can see, my global is a lot shorted, and works better IMO than doing it all the long winded way Tongue

Cheers

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] Accessing Category Description in Detailed page In reply to
Thanks Andy, worked like a charm!
Quote Reply
Re: [shrirch] Accessing Category Description in Detailed page In reply to
The problem is here (nph-build.cgi, line 553):

Code:
Code:
# Only select Category columns that don't conflict with Links columns.
my @cat_cols = grep !$links_cols{$_}, keys %{$DB->table('Category')->cols};
my $sth = $rel->select('Links.*', @cat_cols, 'CategoryID' => $cond);

May someone has an idea how to add:

Select ... "Category.Description as description"?

Then everything should be done.
Quote Reply
Re: [Robert] Accessing Category Description in Detailed page In reply to
Solved it:

Code:
my $sth = $rel->select('Links.*', @cat_cols, 'Category.Description AS description, 'CategoryID' => $cond);