Get a page's root parent's hierarchy-position
Previous article Next articleThis 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>
Comment Form
ReviewManager
ReviewManager
2 Comments
11-04-2016
I updated the UDT and should work now in CMS Made Simple 2.x
06-04-2016
Hi, this no longer works in CMSMS 2.x.
could you post an updated version?
unfortunately the $position no longer works in CMSMS 2.x therefore I would need something similar like your UDT