Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento retrieve children from specific category
    primarykey
    data
    text
    <p>I have a problem with closing my li's and ul's at the correct moment.</p> <p>With the code we have we retrieve all childeren of a specific categorie in the magento shop.</p> <p>Now the problem is that i want to divide all children in lists. So we can have them sorted by category -> sub-category -> sub-sub category. I want my structure to be;</p> <pre><code>&lt;ul&gt; &lt;li&gt; &lt;a&gt;Head Child&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a&gt;Sub child&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a&gt;Sub sub child&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a&gt;Sub sub child&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a&gt;Head Child&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a&gt;Sub child&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a&gt;Sub sub child&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a&gt;Sub sub child&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>The output im getting now is</p> <pre><code>&lt;ul&gt; &lt;a title="View the products for the " href="#"&gt;Head child&lt;/a&gt; &lt;li class="sub_cat"&gt; &lt;a title="View the products for the " href="#"&gt;Sub child&lt;/a&gt; &lt;/li&gt; &lt;li class="sub_cat"&gt; &lt;a title="View the products for the " href="#"&gt;Sub sub child&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>This is our php code;</p> <pre><code>&lt;?php $cat = Mage::getModel('catalog/category')-&gt;load(9); $subcats = $cat-&gt;getChildren(); foreach(explode(',',$subcats) as $subCatid) { $_category = Mage::getModel('catalog/category')-&gt;load($subCatid); if($_category-&gt;getIsActive()) { echo '&lt;ul&gt;&lt;a href="'.$_category-&gt;getURL().'" title="View the products for the "'.$_category-&gt;getName().'" category"&gt;'.$_category-&gt;getName().'&lt;/a&gt;'; $sub_cat = Mage::getModel('catalog/category')-&gt;load($_category-&gt;getId()); $sub_subcats = $sub_cat-&gt;getChildren(); foreach(explode(',',$sub_subcats) as $sub_subCatid) { $_sub_category = Mage::getModel('catalog/category')-&gt;load($sub_subCatid); if($_sub_category-&gt;getIsActive()) { echo '&lt;li class="sub_cat"&gt;&lt;a href="'.$_sub_category-&gt;getURL().'" title="View the products for the "'.$_sub_category-&gt;getName().'" category"&gt;'.$_sub_category-&gt;getName().'&lt;/a&gt;'; $sub_sub_cat = Mage::getModel('catalog/category')-&gt;load($sub_subCatid); $sub_sub_subcats = $sub_sub_cat-&gt;getChildren(); foreach(explode(',',$sub_sub_subcats) as $sub_sub_subCatid) { $_sub_sub_category = Mage::getModel('catalog/category')-&gt;load($sub_sub_subCatid); if($_sub_sub_category-&gt;getIsActive()) { echo '&lt;li class="sub_cat"&gt;&lt;a href="'.$_sub_sub_category-&gt;getURL().'" title="View the products for the "'.$_sub_sub_category-&gt;getName().'" category"&gt;'.$_sub_sub_category-&gt;getName().'&lt;/a&gt;'; } } } } echo '&lt;/ul&gt;'; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload