Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Display Parent Category (Father Category) name in Child Category & on detailed page?

Quote Reply
Display Parent Category (Father Category) name in Child Category & on detailed page?
by using <%GT::Template::dump%> I see FatherID, however I don't see Father Category's name.

Is there any way to display name of Father Category (previous category) on child category page and also on detailed page?

note: Info is technically available in 'title_loop', however, how do I pull that info from there?


Thanks.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
Hey Andy,

I tried using one of your Globals:


Code:
sub {
my $FatherID = shift;
my $sth = $DB->table('Category')->select( { ID => $FatherID } ) || return $GT::SQL::error;
my $Father;
while (my $hit = $sth->fetchrow_hashref) {
$Father = $hit->{ID};
}
$Father ? return $Father : return "Couldnt find a match for ID : $FatherID";
}


However when I call it : <%Fathername_by_id($FatherID)%>

It outputs Father ID # & not the name :( ..

Please help..

--------------------------------
global post @ https://www.gossamer-threads.com/...r%20category#p286345

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
Hi,

A one-liner should do it:

Code:
sub {
return $DB->table('Category')->select( ['Name'], { ID => $_[0] } )->fetchrow || "Couldnt find a match for ID : $_[0]"
}

Call in the same way, and it will reuturn the name of the parent

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!

Last edited by:

Andy: Nov 27, 2019, 9:57 AM
Quote Reply
Re: [Andy] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
There seems to be some error :(


Unable to compile 'Fathername': Global symbol "$FatherID" requires explicit package name at (eval 48) line 2. Global symbol "$FatherID" requires explicit package name at (eval 48) line 2.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
Oops. Try the new version above - or just replace:

Code:
$FatherID

with:

Code:
$_[0]

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] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
Just did.. but it's an error.

Unable to compile 'Fathername': Global symbol "$FatherID" requires explicit package name at (eval 48) line 2.

Vishal
-------------------------------------------------------
Quote Reply
Re: [Andy] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
btw..

Global Name: Fathername

I am calling it using:
<%Fathername($FatherID)%>

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
Ah - there was a bit hidden. Should be:

Code:
return $DB->table('Category')->select( ['Name'], { ID => $_[0] } )->fetchrow || "Couldnt find a match for ID : $_[0]"

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] Display Parent Category (Father Category) name in Child Category & on detailed page? In reply to
Nice ...it worked ...

Awesome SmileSmile

Thank you..

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