Get a page's root parent's hierarchy-position

  Previous article Next article  

Get a page's root parent's hierarchy-position

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.2
  Last updated: 11-04-2016
  Comments: 2

This User Defined Tag gets the hierarchy-position of a pages very top parent.
This article originates from the former CMSMS Wiki and the original author is Calguy1000.

Create a new user-defined tag called "get_root_page_hierarchy" and copy the following code in it.

get_root_page_hierarchy
$assign = isset($params['assign']) ? $params['assign'] : 'root_page_id';

$hm = cmsms()->GetHierarchyManager();

if ( empty($alias) ) $alias = \cms_utils::get_current_alias();

$stack = array();
$node = $hm->find_by_tag('alias',$alias);
while( $node && $node->get_tag('id') > 0 )  {
  $stack[] = $node;
  $node = $node->getParent();
}

if( count($stack) == 0 ) return;
$page_id= $stack[count($stack)-1]->get_tag('id');

$smarty->assign($assign,$page_id);

  How to use

{get_root_page_hierarchy}
<p>The root parent of this page is: {$root_page_id}</p>
{get_root_page_hierarchy assign=foo}
<p>The root parent of this page is: {$foo}</p>

Show related articles:



A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  2 Comments

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

Get a page's root parent's hierarchy-position

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.2
  Last updated: 11-04-2016
  Comments: 2

A2 Webhosting CMS Made Simple