Limiting subcategories in the Prestashop Top Menu
In this quick tip we will see how to limit the number of subcategories the top menu displays in Prestashop.
Watch the Screencast
Text Version
Notice: if you are using a Prestashop version newer than 1.6.0.11, it’s recommended to apply this modification with an override, as explained here: How to override Prestashop modules
Open up modules/blocktopmenu/blocktopmenu.php
Locate the following method:
protected function generateCategoriesMenu($categories, $is_children = 0)
Inside it, you will notice a conditional block
if (isset($category['children']) && !empty($category['children']))
{
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);
if ((int)$category['level_depth'] > 1 && !$is_children)
{
$files = scandir(_PS_CAT_IMG_DIR_);
if (count($files) > 0)
{
$html .= '<li class="category-thumbnail">';
foreach ($files as $file)
if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1)
$html .= '<div><img src="'.$this->context->link->getMediaLink(_THEME_CAT_DIR_.$file)
.'" alt="'.Tools::SafeOutput($category['name']).'" title="'
.Tools::SafeOutput($category['name']).'" class="imgm" /></div>';
$html .= '</li>';
}
}
$html .= '</ul>';
}
We can do a number of things here. If we comment it out, all submenus will be removed. Otherwise, we can reduce and limit the subcategory levels:
if ($category['level_depth'] < 4 && isset($category['children']) && !empty($category['children']))
{
...
In this case, levels over 3 will not be displayed!



