
This post describes how Magento navigation works. I hope it will help you.
The begining of all is in template file: “category/navigation/top.phtml”
1.<ul id="nav">2.< ?php3.foreach ($this->getStoreCategories() as $_category): ?>4.< ?php5.echo $this->drawItem($_category);6.?>7.< ?php endforeach ?>8.</ul>There we call the method from class Mage_Catalog_Block_Navigation $this->getStoreCategories(). This method returns the array $_nodes from object Varien_Data_Tree_Node_Collection.
This array contains objects of Varien_Data_Tree_Node.
Every node is object of Varien_Data_Tree_Node and it is extension from Varien_Object.
Example 1:
If we wish to see how much categories we have, we can do it with method showed below:
1.< ?php2.echo $this->getStoreCategories()->count();3.?>We will get only number of categories from the first level.
Example 2: (only level 1):
01.< ?php02.foreach ($this->getStoreCategories() as $categories)03.{04.// $categories is object Varien_Data_Tree_Node extendec Varien_Object05.06.echo $categories->getData('entity_id')."\n";07.echo $categories->getData('parent_id')."\n";08.echo $categories->getData('level')."\n";09.echo $categories->getData('children_count')."\n";10.}11.?>Every Varien_Data_Tree_Node contains varible $_childNodes
1./**2.* Child nodes3.*4.* @var Varien_Data_Tree_Node_Collection5.*/6.protected $_childNodes;7.**/and $_childNodes is instance of Varien_Data_Tree_Node_Collection.
Varien_Data_Tree_Node_Collection contains variable $_nodes which is array with Varian_Data_Tree_Node.
All this “revolves” through recursion …

