Menus: add a class to FIRST menu item

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Menus: add a class to FIRST menu item

Post by kermit »

example:


Menu One
Menu Two
...


Right now, I've hacked up a menu (below, originally minimal_template.tpl as on this install all menus are only 1 level) using {counter}..

...but there's gotta be an easier way.

Code: Select all

{* CSS classes used in this template:
.currentpage - The active/current page
.bullet_sectionheader - To style section header
hr.separator - To style the ruler for the separator *} 
{if $count > 0}
<div class="sidebox">
<h1>This Section</h1>
{counter assign="countitems" start=0}
<ul class="sidemenu">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{counter assign="countitems" start=0}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{counter assign="countitems" start=0}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}
{if $node->current == true}{counter assign="countitems"}
<li><a href="{$node->url}" {if $countitems == 1}class="currentpage top"{else}class="currentpage"{/if}{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->parent == true && $node->depth == 1}{counter assign="countitems"}
<li class="activeparent"> <a href="{$node->url}" {if $countitems == 1}class="activeparent top"{else}class="activeparent"}{/if}{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->type == 'sectionheader'}{counter assign="countitems"}
<li class="sectionheader">{$node->menutext}

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

{else}{counter assign="countitems"}
<li><a {if $countitems == 1}class="top" {/if}href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{/if}

{/foreach}

{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
</div>
then, the same question could be asked about the very LAST item as well..
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
bterkuile
Forum Members
Forum Members
Posts: 97
Joined: Sun Jul 22, 2007 11:48 am

Re: Menus: add a class to FIRST menu item

Post by bterkuile »

Post Reply

Return to “CMSMS Core”