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

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


Advertisement


Ads help me to help you! Thanks!

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


  Comment Form

Click here to open the form


  6 Comments

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.5
  Last updated: 23-06-2018
  Comments: 6
  http://cms.ms/Dixl

Advertisement


Ads help me to help you! Thanks!

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

Advertisement


Ads help me to help you! Thanks!

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