title: Magento loop inside another loop sub categories with products of that sub category inside
body: <p>I am trying to build a block in Magento (1.8 comunity edition)</p>
  
  <p>In this block I want to seperate the sub categories</p>
  
  <p>lets say that the parent is Power tools</p>
  
  <p>and it has 3 sub categories</p>
  
  <p>saws
  routers
  drills</p>
  
  <p>so the outcome would be something like this...</p>
  
  <p>Power tools
    saws
    routers
    drills</p>
  
  <p>I have the parent category set to display a block, and my existing code will show the sub categories just fine. I get the sub categories output along with their wrapping divs along with the links pointing to the corret subcategory page, but the product lists inside... no joy!</p>
  
  <p>So far I have this for code...</p>
  
  <pre><code>&lt;?php
  
  $category = Mage::getSingleton('catalog/layer')-&gt;getCurrentCategory();
  $categories = $category-&gt;getCollection()
      -&gt;addAttributeToSelect(array('name', 'thumbnail'))
      -&gt;addAttributeToFilter('is_active', 1)
      -&gt;addIdFilter($category-&gt;getChildren())
  ?&gt;
  
  
  
  
  &lt;div class="" style="width: 90%; float:right;margin-right: 5%;"&gt;
  &lt;?php foreach ($categories as $category): ?&gt;
  
      &lt;div class="col-xs-12" style="border: 2px dotted #3t6; font-size: 2em; margin:1em 0;"&gt;
  
          &lt;a href="&lt;?php echo $category-&gt;getUrl() ?&gt;"&gt;&lt;img src="&lt;?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category-&gt;getThumbnail() ?&gt;" alt="&lt;?php echo $this-&gt;htmlEscape($category-&gt;getName()) ?&gt;" /&gt;&lt;/a&gt;
  
  
      &lt;/div&gt;
  
  
  
      &lt;div class="col-xs-12" style="height:200px; border: 1px solid #333;"&gt;
  
  
          &lt;h1&gt;test this&lt;/h1&gt;
          &lt;?php
          $parent_cat = Mage::getModel('catalog/layer')-&gt;getCurrentCategory();
          $_productCollection = $this-&gt;getLoadedProductCollection();
          $_helper = $this-&gt;helper('catalog/output');
          ?&gt;
  
          &lt;?php echo $parent_cat-&gt;getid() ; ?&gt;//this shows the correct id
  
          &lt;?php foreach ($_productCollection as $_product): ?&gt;// start individual products for the sub category
          &lt;?php $_productNameStripped = $this-&gt;stripTags($_product-&gt;getName(), null, true); ?&gt;
                 &lt;h1&gt;&lt;?php echo $_helper-&gt;productAttribute($_product, $_product-&gt;getName() , 'name'); ?&gt;&lt;/
  
  
          &lt;?php endforeach; ?&gt;// end product loop for the individual products
  
      &lt;/div&gt;
  
  
  &lt;?php endforeach; ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So I thought the the $this-> might be referencing the previous call for the outside loop (Not sure though if that makes sense) so I tried something like this...</p>
  
  <pre><code>        &lt;?php
          $parent_cat = Mage::getModel('catalog/layer')-&gt;getCurrentCategory();
          $_productCollection = $parent_cat-&gt;getLoadedProductCollection();
          $_helper = $this-&gt;helper('catalog/output');
          ?&gt;
  </code></pre>
  
  <p>no errors but still no joy.</p>
  
  <p>I am new to loops in Magento so I am totally flailing here, would like it if someone could set me straight on what I am doing wrong.</p>
  
  <p>Thank you!</p>