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

Detrmine the depth of category

Quote Reply
Detrmine the depth of category
Can I use the depth of categories from the user side to display certain componants:
example:
main category - sub category1 - sub category 2 - sub category 3

I want to be able to do something like:

if categorydepth=2 then
x=y
else if categorydepth=3 then
x=y*z
else
do nothing
fi;

thanks
Quote Reply
Re: [Mark2] Detrmine the depth of category In reply to
See the parent_ids() method in GT::SQL::Tree, eg...

Code:
my $PIDS = $DB->table('Categories')->tree()->parent_ids(id => $CategoryID);

Last edited by:

Hargreaves: Dec 6, 2005, 12:56 PM
Quote Reply
Re: [Hargreaves] Detrmine the depth of category In reply to
thanks for the info, but I do not think that is going to help me as I am looking for an admin side solution (simple one)... something like creating a global and if so, how would I do that... or how to check the category depth number
thank you again..
Quote Reply
Re: [Mark2] Detrmine the depth of category In reply to
Hi,

If you're using GLinks 3.x, then you have the <%CatDepth%> option.

Example;

Code:
<%if CatDepth < 3%>
category is less than 3 levels deep
<%elsif CatDepth == 3%>
cat depth is 3
<%else%>
cat depth is greater than 3
<%endif%>

Hope that helps.

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: [Hargreaves] Detrmine the depth of category In reply to
Andy's solution looks better but regarding mine, you could just put the following into a global....

Code:
my $PIDS = $DB->table('Categories')->tree()->parent_ids(id => $CategoryID);
return scalar @$PIDS;

...and I think it would have done the same job.
Quote Reply
Re: [Hargreaves] Detrmine the depth of category In reply to
Thanks Hargreaves and Andy,
I guess since Andy knows about the CatDepth, then I think it is a more practical solution since I am using 3.x and it seems that it is returning an integer; however, and for curiosity, I used Hargreaves gloable, and I referenced it as: <%Category_Depth%> but I got in category page the following line:
my $PIDS = $DB->table('Categories')->tree()->parent_ids(id => $CategoryID); return scalar @$PIDS;
It seems the gloabl did not work or, it is strange that the globales seems not to work on my site.... I never been sucessful in returning creating a globale!!!
Any setting problem... or maybe something in the code??
thanks
Quote Reply
Re: [Mark2] Detrmine the depth of category In reply to
It needs to be enclosed with:

sub {
... the code goes here ...
}


Edit: By the way, you need to pass the category id into the global and then replace $CategoryID with $_[0]

Last edited by:

Hargreaves: Dec 7, 2005, 9:05 AM
Quote Reply
Re: [Hargreaves] Detrmine the depth of category In reply to
I tried CatDepth, however, it is not visable from home.html and when I tried also gloabl from Hargreaves, I still also get the error (I already put the sub {...})...
So what I am trying to do, is to display a different image SIZE for each category/subcategory name, so I need a way to distinquish the following:

if this is a home page, then
image1 size 20x40
if CatDepth => 0, then
image2 size 40x50

any idea...
thank you again and again... ;)
Quote Reply
Re: [Mark2] Detrmine the depth of category In reply to
Hi,

Why not open home.html, and add;

Code:
<%set ishome = 1%>

..then where you have the;

Code:
<%if ishome%>
show what you want here
<%elsif CatDepth > 0%>
show something
<%endif%>

Regarding the global, this would probably be better;

<%global_name($Full_Name)%>

..and with the following code;

Code:
sub {
my @tmp = split /\//, $_[0];
return $#tmp;
}

..as that doesn't do a MySQL query (just passes in what its already got =))

Hope that helps.

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] Detrmine the depth of category In reply to
Thanks much ... worked just fine with the <%set ishome=1%> that was the key...
regards....