Results 1 to 6 of 6
  1. #1

    Default 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!

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default 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
    Zen-Venom Get Bitten

  3. #3

    Default 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:

    PHP Code:
      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:
    PHP Code:
      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?

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default 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 ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default 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 Code:
      function first() {

        
    $trail_size sizeof($this->_trail);

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

      } 
    [1] is the second field in that array.


    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.
    Last edited by gjh42; 29 Oct 2010 at 03:38 PM.

  6. #6

    Default 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:
    PHP Code:
    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!

 

 

Similar Threads

  1. Top Level Category Names
    By autoace in forum General Questions
    Replies: 0
    Last Post: 20 Nov 2009, 11:03 PM
  2. Top level category id
    By rajoo.sharma in forum General Questions
    Replies: 0
    Last Post: 24 Aug 2009, 08:19 AM
  3. Products in top level category
    By mmcs in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 20 Mar 2009, 02:11 PM
  4. Replies: 3
    Last Post: 27 Jan 2008, 02:20 AM
  5. Trying to get "whats_new" products to show on my top level category...
    By dumoti in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 7 Feb 2007, 06:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg