Menu showing only children or siblings of a page

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
rugby
New Member
New Member
Posts: 2
Joined: Wed May 27, 2009 11:04 am

Menu showing only children or siblings of a page

Post by rugby »

How to make a menu, which will show only the children of a page if they exist, otherwise only the siblings of a page? Thanks in advance!
hematec
New Member
New Member
Posts: 8
Joined: Fri Jun 20, 2008 10:49 am

Re: Menu showing only children or siblings of a page

Post by hematec »

Hi,

i had the same problem.

Try the following:

1. Create Userdefined Tag - Name 'Hierarchy' (as in the handbook described)

Code: Select all

global $gCms;
$pos = $gCms->variables['position'];
$base = explode('.', $pos);
$smarty->assign('h_toplevel', $base[0] * 1);
$smarty->assign('h_parent',   $base[ (count($base) > 1) ? count($base)-2 : 0 ] * 1);
$smarty->assign('h_this',     $base[count($base)-1] * 1);
$smarty->assign('h_level',     count($base) * 1);
>> $smarty->assign('h_level',    count($base) * 1) - !!!

2. put the following code in your page template

Code: Select all

{hierarchy}
{assign var="NewLevel" value=$h_level+1}
{assign var='count' value=0}
{if $NewLevel > 1}
  {menu template='AnyTemplateYouWish' number_of_levels='1' collapse='1' start_level="$NewLevel" show_root_siblings='1'}
  {if $count == 0 && $NewLevel > 2}
    {menu template='AnyTemplateYouWish' number_of_levels='1' collapse='1' start_level="$h_level" show_root_siblings='1'}
  {/if}
{/if}
What we do is try to get a menu with the Param '$NewLevel' which represents the Level of the current pages Children.
If this fails the value $count will be 0 and we should try to list the nodes on the same level as the current page ($h_level').($count is set by the menumanger and represents the number of Nodes in the menu)

In the code Listed above i do NOT list toplevel Nodes!! It starts at atleast Level 2!

I hope this helps.
Post Reply

Return to “Layout and Design (CSS & HTML)”