MENU

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

  Previous article Next article  

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:


  Comment Form

Click here to open the form


  2 Comments

CMS Made Simple - Tutorials, tips and tricks - CMSMS

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: 2
  http://cms.ms/COjt

Advertisement



Ads help me to help you! Thanks!

Ads help me to help you! Thanks!

Ads help me to help you! Thanks!