Nick Shaw

Add category ID as a class to the body tag in Prestashop

Within CategoryController.php’s initContent() function find “$this->context->smarty->assign(array(” and add a new line:

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

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}>

Code from Prestashop forum

Exit mobile version