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();

$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>

Buy Me A Coffee


  Show related articles:


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  2 Comments

Buy Me A Coffee

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.14
  Last updated: 06-06-2020
  Comments: 2
  http://cms.ms/COjt


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!