Get Page Title (not covered in cheat sheet)

Permalink
Hi There

I am trying to make a statement to adapt my theme outside of autonav.

I need to say basically:

IF page level = below 1 THEN print parent title
ELSE print page title

However I cant work out how to say the print page title bit as the copy from the Cheat sheet deonst work in this context and I am not that shot at PHP.

So far I have the below - what should go where the XXX is. Any help greatly appreciated.

Thanks
<?php
$root = Page::getCurrentPage();
$parent = Page::getByID($c->getCollectionParentID()); 
if ( $root->getCollectionParentID() != 1){
echo $parent->getCollectionName();
}
else {
echo XXXXX;}
?>

 
12345j replied on at Permalink Reply
12345j
$root->getCollectionName()

You assign the variable root to the current page with $root=Page::getCurrentPage(); Root now holds the page object, which you get information about the page from, so making a call to get the name of root calls the current name.
tobyme replied on at Permalink Reply
Thanks for that - so my final code was:
<?php
$root = Page::getCurrentPage();
$root->getCollectionName();
$parent = Page::getByID($c->getCollectionParentID()); 
if ( $root->getCollectionParentID() != 1){
echo $parent->getCollectionName();
}
else {
echo ('<a href="http://www.myparentpage.com">' . $root->getCollectionName() . '</a>');
}
?>


Just wondering how would I go about making what is currently a static link, a link to the parent page? Clearly out of my depth but once thats done itll all be a nice submenu.

Thanks