Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have relatively the same idea on the website I'm working on, where I display sub-categories in a grid view. While I used to use the method of individually loading category/product information by id's, I sort of fell in love with using the "Mage::getModel('')->getCollection()" method.</p> <p>This is what I've used on my sub categories, and I've been quite happy with it, as it grabs all the information at once:</p> <pre><code>&lt;?php if(Mage::registry( 'current_category' )-&gt;getId()) { $_currentCategoryId = Mage::registry( 'current_category' )-&gt;getId(); } else { //Get Root Category Id if not in a category $_currentCategoryId = Mage::app()-&gt;getStore()-&gt;getRootCategoryId(); } $_subCategories = Mage::getModel( 'catalog/category' )-&gt;getCollection() -&gt;addAttributeToSelect('*') -&gt;addFieldToFilter('parent_id',array('eq' =&gt; $_currentCategoryId)) -&gt;addFieldToFilter('include_in_menu',array('eq' =&gt; '1')) -&gt;addFieldToFilter('is_active', array('eq' =&gt; '1')) -&gt;addAttributeToSort('position', 'asc'); ?&gt; &lt;?php if(count($_subCategories) &gt; 0): ?&gt; &lt;!--This is where the sub-category layout would go.--&gt; &lt;?php else: ?&gt; &lt;!--Do something else if there are no sub-categories.--&gt; &lt;?php endif; ?&gt; </code></pre> <p>This will grab all visible sub-categories of the current category, OR grab the base categories (from Root Category Id) of the store, if you choose to have the template show on any other page. You could go further and define specific attributes with addAttributeToSelect as well.</p>
    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.
    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