Jump to content

Get grandparent category ID?


yay

Recommended Posts

I have a three level category structure that looks something like this:

  1. Women
    1. ​Tops
      1. Blouses
      2. Jackets
    2. Shoes
      1. Casual shoes
      2. Training shoes
  2. Men
    1. Shirts
      1. Long-sleeve
      2. Short-sleeve
    2. Shoes
      1. Sneakers
      2. Trainers

​I want to use a certain color for styling elements on all Men categories and another color for all Women categories. So all sub-categories and sub-sub-categories should have the same color as their "grandparent" category. So my solution was to add this to the body class tag in header.tpl.

{if $page_name == 'category'} category-{$id_category_parent}{/if}

This works great but only for two levels. When I'm in say the Blouses category on level 3, the returned parent ID will of course be Tops instead of Women. I know there is a $category->level_depth command that might be helpful but I still can't figure out how to access the "grandparent" category ID for level 3 categories. Any ideas?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...