Page 1 of 1

[Solved] Basic Horizontal Menu with Selected Menu Items

Posted: Thu Apr 16, 2015 2:34 pm
by apollo9
I've been trying to reinstate a very basic horizontal menu at the top of our website containing selected menu items, some parent, some child.
It needs to be displayed in one line, with the same styling.

Currently, the menu displays inline - but parent items are on the top line, child items are on the line below and styled as per li li.

Here's the site with menu as described. http://cornworthy.com.gridhosted.co.uk/cms/

I'm calling the menu as such

Code: Select all

{menu template='corn2_menu_header' number_of_levels='1' items='home,events-activities,website-contacts,gardeners-world,search-your-ancestors'}
The menu template copied from another menu:

Code: Select all

{assign var='number_of_levels' value=10000}
{if isset($menuparams.number_of_levels)}
  {assign var='number_of_levels' value=$menuparams.number_of_levels}
{/if}

{if $count > 0}
<div id="corn2_menu_header">

<ul>
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->parent == true or $node->current == true}
  {assign var='classes' value='selected'}
  {if $node->parent == true}
    {assign var='classes' value='selectedparent'}
  {/if}
  {if $node->children_exist == true and $node->depth < $number_of_levels}
    {assign var='classes' value=$classes|cat:' parent'}
  {/if}
  <li class="{$classes}"><a class="{$classes}" href="{$node->url}"><span>{$node->menutext}</span></a>

{elseif $node->children_exist == true and $node->depth < $number_of_levels and $node->type != 'sectionheader' and $node->type != 'separator'}
<li class="parent"><a class="parent" href="{$node->url}"><span>{$node->menutext}</span></a>

{elseif $node->current == true}
<li class="currentpage"><h3><span>{$node->menutext}</span></h3>

{elseif $node->type == 'sectionheader'}
<li class="sectionheader"><span>{$node->menutext}</span>

{elseif $node->type == 'separator'}
<li class="separator" style="list-style-type: none;"> <hr />

{else}
<li><a href="{$node->url}"><span>{$node->menutext}</span></a>

{/if}

{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
</div>
{/if}
Hope someone can provide some ideas. Expect I'm missing something obvious!

Chris

Re: Basic Horizontal Menu with Selected Menu Items

Posted: Thu Apr 16, 2015 11:11 pm
by paulbaker
Too many <ul>s.

Try changing

Code: Select all

{repeat string="<ul>" times=$node->depth-$node->prevdepth}
in to

Code: Select all

{* repeat string="<ul>" times=$node->depth-$node->prevdepth *}
(i.e. comment it out)

Re: Basic Horizontal Menu with Selected Menu Items

Posted: Fri Apr 17, 2015 1:35 pm
by apollo9
Excellent! Thank you!