Zen Cart Logo
Forums / All Other Contributions/Addons / Get Top Level Category Name

Get Top Level Category Name

Locked

Views: 2,775

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
29 Oct 2010, 7:36 AM
#1
kidsstuff avatar

kidsstuff

New Zenner

Join Date:
Oct 2010
Posts:
44
Plugin Contributions:
0

Get Top Level Category Name

Hi all,
I need a way to get the top level category name from within the category sidebox.

Ex: I have these categories: Tables>Dining Tables>Metal>Product

When browsing any subcategory/product page from within Tables, I need that name fo something like: "You're now browsing Tables".
Only need to know how to get that name, the rest is simple.

Any pointers are greatly appreciated!

29 Oct 2010, 8:10 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Get Top Level Category Name

For the php to extract you might find it in
/includes/classes/breadcrumb.php
and/or
/includes/init_includes/init_add_crumbs.php

29 Oct 2010, 9:03 AM
#3
kidsstuff avatar

kidsstuff

New Zenner

Join Date:
Oct 2010
Posts:
44
Plugin Contributions:
0

Re: Get Top Level Category Name

Thanks Cobra.
I'm looking at how $breadcrumb->last() function works in tpl_index categories.php.

So I made another function inside breadcrumb.php, like:

  function first() {

    $trail_size = sizeof($this->_trail);

    return $this->_trail[$trail_size-2]['title'];

  }

Which works fine, but now i'm stuck on how to make that number what I need. I tried:

  function first() {

    $trail_size = sizeof($this->_trail);

    return $this->_trail[$trail_size-($trail_size-1]['title'];

  }

, which gave me this error: PHP Fatal error: Using $this when not in object context.

What else can I try?

29 Oct 2010, 2:21 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Get Top Level Category Name

See if this works for you:
(int)$_GET['cPath']

That is available when navigating the Category Tree ...

When cPath is 3_10, the results would be 3 ...

29 Oct 2010, 2:35 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Get Top Level Category Name

Since you want the top category name, which will always be the second item in the trail after Home, how about this```php
function first() {

$trail_size = sizeof($this->_trail);

return $this->_trail[1]['title'];

}



Or yes, use the information globally available instead of making a new function. You can use an existing zen_get... function to get the category name from the id that Linda's suggestion yields.
29 Oct 2010, 6:36 PM
#6
kidsstuff avatar

kidsstuff

New Zenner

Join Date:
Oct 2010
Posts:
44
Plugin Contributions:
0

Re: Get Top Level Category Name

Thanks a lot!
Linda, I tried that, which brings up the id number of the top level category, but it works only for index pages, not for product pages, for which it brings up 0.

I tried with:

zen_get_category_name((int)$_GET['cPath'], (int)$_SESSION['languages_id'])

Glenn, thank you very much for the get_zen function hint, I found it using the developers toolkit.

It is now working great using that function in breadcrumb.php.
This was fun, I learned a lot today! :flex: