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:
[php]
protected function generateCategoriesMenu($categories, $is_children = 0)
[/php]
Inside it, you will notice a conditional block
[php]
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>’;
}
[/php]
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:
[php]
if ($category[‘level_depth’] < 4 && isset($category[‘children’]) && !empty($category[‘children’]))
{
…
[/php]
In this case, levels over 3 will not be displayed!
Need PrestaShop Modules? Have a look at my Prestashop Addons Store!
Looking for quality PrestaShop Web Hosting? Look no further than Arvixe Web Hosting!