How can I add categories to a static block so that I can call that block in my footer section.
the above image is from footer and I want to insert all my categories there.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow can I add categories to a static block so that I can call that block in my footer section.
the above image is from footer and I want to insert all my categories there.
Try to put this in a new file say footer_categories.phtml
:
<div class="footer_categories">
<ul>
<?php $helper = $this->helper('catalog/category') ?>
<?php foreach ($helper->getStoreCategories() as $_category): ?>
<li>
<a href="<?php echo Mage::getModel('catalog/category')->setData($_category->getData())->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a>
</li>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml() ?>
Now open your static block and call in this way
{{block type="core/template" template="catalog/footer_categories.phtml"}}
you can get the required output.
I assume you added some php code directly in the static block.
That won't work. Magento does not support php in the static blocks. And that's a good thing.
It only supports html and {{}}
directives.
So what you need to do is to create a template file. Let's call it footer_categories.phtml
You can place it in app/design/frontend/{package}/{theme}/template/catalog/footer_categories.phtml
where you place the code you added directly in the block.
Then edit the static block and replace the code you added with this:
{{block type="core/template" template="catalog/footer_categories.phtml"}}
[EDIT]
Here is the code you need to place in the template
<?php
$root = Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1) //only active categories
->setOrder('position', 'ASC');
?>
<?php foreach ($categories as $category) :?>
<a href="<?php echo $category->getUrl();?>"><?php echo $category->getName();?></a>
<?php endforeach;?>
Of course this may look ugly but you can handle the css part.
If want to call you category static blogon category then just call
below code at footer.phtml
if(Mage::registry('current_category')){
if(Mage::registry('current_category')->getLandingPage()):
$this->getLayout()->createBlock('cms/block')
->setBlockId(Mage::registry('current_category')->getLandingPage())
->toHtml();
endif;
}
According to magento logic static block id save at landing_page
field of category object
if($_category->getLandingPage()):
$this->getLayout()->createBlock('cms/block')
->setBlockId($_category->getLandingPage())
->toHtml();
endif;
Follow simple step might helps you.
1)Create a static block for the content you want to use between categories.
2)Now go back to manage categories, and find your category
3)Select display mode “Static block and products”
4)Select the static block you created in step 1. The static block will appear above the list of products.
Get collection of all active categories:
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*');
Get collection of all active categories within a subcategory:
$parentCategoryId = '9';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addFieldToFilter('parent_id', array('eq'=>$parentCategoryId))
->addFieldToFilter('is_active', array('eq'=>'1'))
->addAttributeToSelect('*');
Get collection of all active and inactive categories within a subcategory:
$parentCategoryId = '9';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addFieldToFilter('parent_id', array('eq'=>$parentCategoryId))
->addFieldToFilter('is_active',array("in"=>array('0', '1')))
->addAttributeToSelect('*');
Get collection of all inactive categories within a subcategory:
$parentCategoryId = '9';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addFieldToFilter('parent_id', array('eq'=>$parentCategoryId))
->addFieldToFilter('is_active', array('neq'=>'1'))
->addAttributeToSelect('*');