title: Printing out a nested list of categories from Magento using a recursive function
body: <p>So I have the following code in /[my-theme-name]/template/catalog/navigation/left.phtml as a proof of concept:</p>
  
  <pre><code>&lt;?php
  $Mage_Catalog_Block_Navigation = new Mage_Catalog_Block_Navigation();
  $categories = $Mage_Catalog_Block_Navigation-&gt;getStoreCategories();
  
  function render_flat_nav($categories) {
      $html = '&lt;ul&gt;';
      foreach($categories as $category) {
          $html .= '&lt;li&gt;&lt;a href="' . $category-&gt;getCategoryUrl($cat) . '"&gt;' . 
                    $category-&gt;getName() . "&lt;/a&gt;\n";
          if($category-&gt;hasChildren()) {
              $children = $category-&gt;getChildren();
              $html .= render_flat_nav($children);
          }
          $html .= '&lt;/li&gt;';
      }
      return $html . '&lt;/ul&gt;';
  }
  echo render_flat_nav($categories); ?&gt;
  </code></pre>
  
  <p>It works great for level 0 and level 1 categories but any categories that are more deeply nested are never printed out.</p>
  
  <p>So <code>$category-&gt;getChildren()</code> can't quite be returning what I expect it to. Is there a method I can call that will work with my recursive function?</p>