Getting a page's root parent's alias

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
binarybee

Getting a page's root parent's alias

Post by binarybee »

I needed a way to get the alias of a pages very top parent and calguy1000 on the IRC channel assisted me.

The code he has come up with is as follows...

Code: Select all

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_alias';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Alias();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);
Create a new user-defined tag called get_root_page_alias and copy in the above code.

The tag can be called using...

Code: Select all

{get_root_page_alias assign="varname"}
An example use would be...

Code: Select all

{get_root_page_alias assign="root_page_alias"}The root parent of this page is:{$root_page_alias}
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Getting a page's root parent's alias

Post by Dee »

haapati
Forum Members
Forum Members
Posts: 20
Joined: Sun Sep 10, 2006 4:14 pm

Re: Getting a page's root parent's alias

Post by haapati »

This code doesn't work? I have CMSMS version 0.13. When I put the tag into the template code it stop printing after that.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Getting a page's root parent's alias

Post by Dee »

I think this will only work on 1.0.
haapati
Forum Members
Forum Members
Posts: 20
Joined: Sun Sep 10, 2006 4:14 pm

Re: Getting a page's root parent's alias

Post by haapati »

Yes, I just noticed the same thing.

So, I made a code which will work in version 0.13.

Code: Select all

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['content_id'];
$node =& $manager->sureGetNodeById($thisPage);


$node_data = (get_object_vars($node));
$parent_node = (get_object_vars($node_data[parentNode]));
$parent_node_content = (get_object_vars($parent_node[content]));

echo $parent_node_content[mAlias];
This print page's root parent alias.
Last edited by haapati on Wed Sep 27, 2006 11:13 am, edited 1 time in total.
ostricized

Re: Getting a page's root parent's alias

Post by ostricized »

Is it possible to get the root page title?
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: Getting a page's root parent's alias

Post by nils73 »

Do you mean as a tag or the title-attribute of the root-page? As far as I know you can get the title-attribute if it is set.

Regards,
Nils
ostricized

Re: Getting a page's root parent's alias

Post by ostricized »

Hi Nils73!

I am looking for the root page title value (attribute?), more specifically, the magic syntax to obtain that value just like what the 2 examples in this thread accomplish.

Thank you very much in advance if anyone is willing to part with this information =)
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: Getting a page's root parent's alias

Post by nils73 »

ostricized,

you can use all values out of MenuManger, so the title-attribute should be obtained like this:

1. Create a user-defined tag called "get_parent_title" with following values

Code: Select all


global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_title';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Titleattribute();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);

2. Put the following code into your website:

Code: Select all


{get_title assign="root_page_title"} The root parents' title of this page is:{$root_page_title}

This should do the trick.

Regards,
Nils
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Getting a page's root parent's alias

Post by calguy1000 »

Four new methods in the CustomContent module do this:

$ccuser->get_parent_alias($alias = '')  get_root_alias($alias = '') get_page_title($alias = '') has_children($alias = '')  <-- output a boolean indicating if the specified page has children (use current page if no page is specified)

Just thought I'd let you know.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
joecannes
Forum Members
Forum Members
Posts: 93
Joined: Mon Nov 26, 2007 5:00 pm

Re: Getting a page's root parent's alias

Post by joecannes »

I've inserted the code for getting the parent title, still not working...I am using CMSMS 1.2.3, and I do have the title defined.

All I get is:

The root parents' title of this page is:

and then it is blank
Post Reply

Return to “Tips and Tricks”