Jump to content

Add default category class ID to product page body


Recommended Posts

Hi

 

Looking for a solution to add the default product category id class to the body id of each product.

 

i.e. <body id="product" class="cat?"> "cat?" being the default category id of the product.

 

Code snippet and solution would be great if anyone out there can help..?

 

Kind regards

Nick

Link to comment
Share on other sites

Hi... 

 

Did a similar form this post: http://www.prestashop.com/forums/topic/285562-custom-class-for-body-depending-on-category/

 

as below.. seemed to work great..

 

Within CategoryController.php's initContent() function you can add something like:

 

'parent_category_chain' => $this->category->getParentsCategories(), 

 

to the "$this->context->smarty->assign(array(" smarty assignment.

 

Then in your header.tpl you can use a foreach loop to only add a category id number where the level_depth of categories is equal to 2 (which would all have a parent category of "home" respectively).

 

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}{if $category->id}{if $category->level_depth eq 2} class="cat{$category->id}"{elseif $category->level_depth > 2}{foreach $parent_category_chain as $parent_category_node}{if $parent_category_node.level_depth eq 2} class="cat{$parent_category_node.id_category}"{/if}{/foreach}{/if}{/if}>

Link to comment
Share on other sites

  • 2 years later...

Hello not working on Presta 1.6.1.11 in product page but working on category page...

 

hello litle edit so  =

 

Where to Buy / Eastern Europe /Russia > Edinorog LLC

 

 

What i want is the first category after home. In categoryit's working i kann see my default with:

            {foreach $parent_category_chain as $parent_category_node}
                {if $parent_category_node.level_depth eq 2}
                {assign var=wheretobuy value=$parent_category_node.id_category}
                {/if}
            {/foreach}

i try with a different value on level_depth but....

Edited by Tatort (see edit history)
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...