Jump to content

top horizontal menu - max level depth


Recommended Posts

I need to set the maximum depth for top horizontal menu items. Presta 1.5.1, the standard module blocktopmenu, based on superfishmenu.

 

 

 

How to do it?

 

Depth should not depend on the settings of the module blockcategories.

 

Help please...

Link to comment
Share on other sites

In modules/blocktopmenu/blocktopmenu.php

Inside the function getCategory, around line 645 you should see this code:

if (!empty($is_intersected))
               {
                       $this->_menu .= '<li '.$selected.'>';
                       $this->_menu .= '<a href="'.$category_link.'">'.$category->name.'</a>';

                       [b]if (count($children))[/b]
                       {
                               $this->_menu .= '<ul>';

                               foreach ($children as $child)
                                       $this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);

                               $this->_menu .= '</ul>';
                       }
                       $this->_menu .= '</li>';
               }
       }

If i replace line with code

if (count($children))

on this

if(count($children) & ($ddd=1))

i have menu depth with one sub-level

but those who have depth 3 or 2 do not show any sub-levels (no 1 or 2 or 3 sub-level menu and items)

 

If i replace line with code

if (count($children))

on this

if(count($children) & ($ddd=2))

i have menu depth with two sub-level

but those who have depth 1 do not show :unsure:

 

how to combine the conditions? :ph34r:

Link to comment
Share on other sites

  • 8 months later...

In modules/blocktopmenu/blocktopmenu.php

Inside the function getCategory, around line 645 you should see this code:

if (!empty($is_intersected))
			{
					$this->_menu .= '<li '.$selected.'>';
					$this->_menu .= '<a href="'.$category_link.'">'.$category->name.'</a>';

					[b]if (count($children))[/b]
					{
							$this->_menu .= '<ul>';

							foreach ($children as $child)
									$this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);

							$this->_menu .= '</ul>';
					}
					$this->_menu .= '</li>';
			}
	}

If i replace line with code

if (count($children))

on this

if(count($children) & ($ddd=1))

i have menu depth with one sub-level

but those who have depth 3 or 2 do not show any sub-levels (no 1 or 2 or 3 sub-level menu and items)

 

If i replace line with code

if (count($children))

on this

if(count($children) & ($ddd=2))

i have menu depth with two sub-level

but those who have depth 1 do not show :unsure:

 

how to combine the conditions? :ph34r:

 

 

Hey i,m facing kinda same problem. i don't want any subcategories. I mean zero level. Do you know how to do it ?

Link to comment
Share on other sites

  • 7 years later...

Hello!

I have posted this in other thread which discuss same problem: FIXED

In the Top Menu I needed to limit the Categories detail level to 1.
I'm no expert coder at all, so please be kind... may be I performed major surgery instead being a bit more gentle 🙃

-- PS ver 1.7.6.8
-- File modules/ps_mainmenu/ps_mainmenu.php
-- Line 715  protected function "generateCategoriesMenu"
-- Disabled (commented) lines 746 to 761 as follows

            /*if (isset($category['children']) && !empty($category['children'])) {
                $node['children'] = $this->generateCategoriesMenu($category['children'], 1);

                if ($this->imageFiles === null) {
                    $this->imageFiles = scandir(_PS_CAT_IMG_DIR_);
                }

                if (count(preg_grep('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $this->imageFiles)) > 0) {
                    foreach ($this->imageFiles as $file) {
                        if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1) {
                            $image_url = $this->context->link->getMediaLink(_THEME_CAT_DIR_.$file);
                            $node['image_urls'][] = $image_url;
                        }
                    }
                }
            }*/
-- Advanced Parameters, Performance, Smarty -> Save

image.png

-- Just in case, hit "Clear Cache" top right button
-- Tested, Worked for me!

Hope this can help.

 

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