Page 1 of 1

max submenu items

Posted: Wed Dec 28, 2011 6:41 pm
by sandertimmermans
Hi,

Can anyone help me with my following problem:

I've created a site with 2 vertical divs. div1 for the main menu and div2 for the submenu.
The height of the divs are fixed. So if i create several subitems (projects in this case), the list is getting to large. Is there a way to set a maximum of submenu items? I want to create a link at the bottom of div2 to link to page 2.

Kind regards,

Sander

Re: max submenu items

Posted: Wed Dec 28, 2011 7:29 pm
by Dr.CSS
There is no way to tell menus to only show X amount of items...

Re: max submenu items

Posted: Wed Dec 28, 2011 7:32 pm
by sandertimmermans
Hi Dr.Css,

Is there another way to fix my problem?

Kind regards,

Sander

Re: max submenu items

Posted: Wed Dec 28, 2011 9:07 pm
by Wishbone
I'm assuming that you are using two different {menu} calls.. One for the main menu, and another for the submenu.

if so, you could put a counter in your menu template and have it stop after a certain number is reached.

Assuming your submenu (maybe in a sidebar?) is being called like:

{menu childrenof=$page_alias number_of_levels=1}
(or start_level=2 instead of the childrenof parameter)

you can modify your template like:

Code: Select all

{assign var=count value=0}
{foreach .....}
{if $count<5}
:
:
{* rest of template inside the foreach loop *}
:
:
{/if}
{assign var=count value=$count+1}
{/foreach}
In the example above, it clears out a counter, and increments it for each menu item shown. Once it hits 5 (or whatever), the remaining items stops being processed.

If you have sub-sub menu items being displayed (no number_of_levels parameter), then the count will be skewed, since it's also counting the sub-sub menu items.. You would have to keep track of the depth before incrementing the counter.