Page 1 of 1

Previous and next links only for the current item

Posted: Fri Jul 03, 2009 11:18 am
by gap_tooth_clan
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}

Re: Previous and next links only for the current item

Posted: Sun Jul 05, 2009 10:24 am
by RonnyK
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.
{$cgsimple->get_sibling("prev","prev_sibling")}{if !empty($prev_sibling)}{cms_selflink page="$prev_sibling" text="Previous"}{/if}
And the same for the next sibling
{$cgsimple->get_sibling("next","next_sibling")}{if !empty($next_sibling)}{cms_selflink page="$next_sibling" text="Next"}{/if}
Ronny

Re: Previous and next links only for the current item

Posted: Mon Jul 06, 2009 8:59 am
by gap_tooth_clan
Ha ha awesome, much better

Re: Previous and next links only for the current item

Posted: Thu Jul 16, 2009 4:41 pm
by steven_germany
Ronny: Perfect! Thank you very much for this tip!