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.2.5
  Last updated: 23-12-2017
  Comments: 0
  http://cms.ms/COjt

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
$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');

echo $page_id;

  How to use

<p>The root parent of this page is: {get_root_page_hierarchy}</p>

Show related articles:





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

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

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.5
  Last updated: 23-12-2017
  Comments: 0
  http://cms.ms/COjt