Skip to content

Instantly share code, notes, and snippets.

@myinitialsaretk
Created April 11, 2013 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myinitialsaretk/5367245 to your computer and use it in GitHub Desktop.
Save myinitialsaretk/5367245 to your computer and use it in GitHub Desktop.
Magento CMS Hierarchy Stub. This is mostly useless, but just saving for myself for reference.
<div class="nav-container sidebar-nav">
<ul class="nav nav-list">
<?php
$currentPage = $this->getHelper('cms/page')->getPage()->getPageId();
$currentPageParent = '';
$outputNodes = Array();
$collection = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()->joinCmsPage()->setTreeOrder();
foreach ($collection as $item) {
if ($item->getPageId() == $currentPage)
$currentPageParent = $item->getParentNodeId();
}
foreach ($collection as $item) {
if ($item->getParentNodeId() == $currentPageParent) { // This Page Shares a Parent
/* @var $item Enterprise_Cms_Model_Hierarchy_Node */
$node = array(
'node_id' => $item->getId(),
'parent_node_id' => $item->getParentNodeId(),
'label' => $item->getLabel(),
'page_exists' => (bool)$item->getPageExists(),
'page_id' => $item->getPageId(),
'url' => $item->getUrl()
);
if ($item->getPageId() == $currentPage)
$node['current'] = true;
$outputNodes[] = $node;
}
}
if ($outputNodes) {
foreach($outputNodes as $node) {
if ($node['current'])
echo '<li class="active" ><a href="' . $node['url'] . '"><span>' . $node['label'] . '</span></li>';
else
echo '<li><a href="' . $node['url'] . '"><span>' . $node['label'] . '</span></li>';
}
}
?>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment