MENU

Get a page's root parent's alias

  Previous article Next article  

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

Note: Similar functionality is provided by the CGSimpleSmarty module's {cgsimple::get_root_alias()} tag.


Create a new User Defined Tag called "get_root_page_alias" and copy the following code in it:

$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;
$alias = $stack[count($stack)-1]->get_tag('alias');

echo $alias;

  How to use

The tag can be called using:

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

  Working example

I used it in my multilingual template.


Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  6 Comments

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Get a page's root parent's alias

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.14
  Last updated: 06-06-2020
  Comments: 6
  http://cms.ms/Dixl


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

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