Magento – Get page title and link of parent CMS page in CMS Hierarchy

cmsmagento-enterpricemagento-enterprisenavigationpage-title

Is there a good method for retrieving the page title and url of the parent CMS page when using Magento's CMS Hierarchy?

Example Structure:

  • About Us
    • Culture
    • Contact

I need to be able to get the About Us page title on Culture and Contact pages.

The only method I've come up with is this terrible code which grabs the parent page's title:

<?php echo ($_tree[0][3]->getData("page_title")); ?>

Right now it's showing the current page title instead of the parent page title: http://grab.by/Drl4 as I'm using the code:

<?php echo str_replace(Mage::getStoreConfig('design/head/title_prefix'), '', $this->getLayout()->getBlock('head')->getTitle()); ?>

Any ideas of a reusable and clean method to grab the parent CMS page's title and url?

side note : I have editition with me.

Best Answer

Here is the solution for you:

if ($currentNode = Mage::registry('current_cms_hierarchy_node')) {
    // Zend_Debug::dump($currentNode->getData());
    $parentId       = $currentNode->getParentNodeId();
    $parentNode  = Mage::getModel('enterprise_cms/hierarchy_node')
        ->load($parentId);
    // Zend_Debug::dump($parentNode->getData());

    $parentTitle    = $parentNode->getPageTitle();
    $parentUrl      = Mage::getUrl($parentNode->getRequestUrl());
    // Zend_Debug::dump($parentTitle);
    // Zend_Debug::dump($parentUrl);
}

You can run this code from any .phtml file.