I wanted previous and next links that only showed me pages within the current hierarchy.
Thanks to hematec who I took the majority of this code from.
http://forum.cmsmadesimple.org/index.php?topic=34180.0
Create a UDT called hierarchy
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('f_position', $gCms->variables['friendly_position']);
$smarty->assign('f_base', (int)$gCms->variables['friendly_position']);
and put this in your template
{hierarchy}
{assign var="NewLevel" value=$h_level+1}
{assign var='count' value=0}
{assign var="f_pos_next" value=$f_position+0.1}
{assign var="f_pos_prev" value=$f_position-0.1}
{assign var="f_base" value=$f_base}
{assign var="f_ceil" value=$f_base+1}
{if $NewLevel > 1}
{if $f_pos_next {menu template='V2 Main Menu' start_element=$f_pos_next number_of_levels="1"}
{/if}
{if $f_pos_prev >= $f_base}
{menu template='V2 Main Menu' start_element=$f_pos_prev number_of_levels="1"}
{/if}
{/if}
Previous and next links only for the current item
Re: Previous and next links only for the current item
Or use CGSimpleSmarty,
which has the parameters included, to know if a page is a sibling....
F.e. this logic, coming from the help of CGSimpleSmarty, which could be set in the template.
which has the parameters included, to know if a page is a sibling....
F.e. this logic, coming from the help of CGSimpleSmarty, which could be set in the template.
And the same for the next sibling{$cgsimple->get_sibling("prev","prev_sibling")}{if !empty($prev_sibling)}{cms_selflink page="$prev_sibling" text="Previous"}{/if}
Ronny{$cgsimple->get_sibling("next","next_sibling")}{if !empty($next_sibling)}{cms_selflink page="$next_sibling" text="Next"}{/if}
-
- Forum Members
- Posts: 34
- Joined: Tue Apr 21, 2009 6:52 pm
Re: Previous and next links only for the current item
Ronny: Perfect! Thank you very much for this tip!