How can I add categories to a static block so that I can call that block in my footer section. enter image description here
the above image is from footer and I want to insert all my categories there.
-
are you want to show this block on category page footerAmit Bera– Amit Bera ♦2014年11月19日 07:21:52 +00:00Commented Nov 19, 2014 at 7:21
-
please have a look at my edited contentAbdul– Abdul2014年11月19日 07:24:13 +00:00Commented Nov 19, 2014 at 7:24
4 Answers 4
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.
-
and can you please tell me what code added to footer_categories.phtml to get all the categories.Abdul– Abdul2014年11月19日 07:45:29 +00:00Commented Nov 19, 2014 at 7:45
-
By the looks of your screenshot I think you already have the code. Please post in the question the code you added directly in the static block and I'll tell you if it's ok or not.Marius– Marius2014年11月19日 07:49:52 +00:00Commented Nov 19, 2014 at 7:49
-
actually I followed the procedure mentioned by zack in his answer and it resulted in that way :(Abdul– Abdul2014年11月19日 07:51:28 +00:00Commented Nov 19, 2014 at 7:51
-
You want all the categories or only the top level ones?Marius– Marius2014年11月19日 07:52:22 +00:00Commented Nov 19, 2014 at 7:52
-
Only the main categories no sub categoriesAbdul– Abdul2014年11月19日 07:53:04 +00:00Commented Nov 19, 2014 at 7:53
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;
-
I want all my categories into a static block and then I can call them in my footerAbdul– Abdul2014年11月19日 07:32:27 +00:00Commented Nov 19, 2014 at 7:32
-
for ex I have categories like mens womens children all this catgories should be visible in my footer and also should have href's so when user click on mens then he shoudl get mens category pageAbdul– Abdul2014年11月19日 07:33:46 +00:00Commented Nov 19, 2014 at 7:33
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('*');
-
please have a look at my edited contentAbdul– Abdul2014年11月19日 07:24:38 +00:00Commented Nov 19, 2014 at 7:24
-
1Can you make this answer clearer - it appears to suggest using PHP in the static block with will not work.Jonathan Hussey– Jonathan Hussey2014年11月19日 07:53:29 +00:00Commented Nov 19, 2014 at 7:53