1

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.

2
  • are you want to show this block on category page footer
    – Amit Bera
    Nov 19, 2014 at 7:21
  • please have a look at my edited content
    – Abdul
    Nov 19, 2014 at 7:24

4 Answers 4

1

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.

3

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.

6
  • and can you please tell me what code added to footer_categories.phtml to get all the categories.
    – Abdul
    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
    Nov 19, 2014 at 7:49
  • actually I followed the procedure mentioned by zack in his answer and it resulted in that way :(
    – Abdul
    Nov 19, 2014 at 7:51
  • You want all the categories or only the top level ones?
    – Marius
    Nov 19, 2014 at 7:52
  • Only the main categories no sub categories
    – Abdul
    Nov 19, 2014 at 7:53
0

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;
2
  • I want all my categories into a static block and then I can call them in my footer
    – Abdul
    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 page
    – Abdul
    Nov 19, 2014 at 7:33
0

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('*');
2
  • please have a look at my edited content
    – Abdul
    Nov 19, 2014 at 7:24
  • 1
    Can you make this answer clearer - it appears to suggest using PHP in the static block with will not work. Nov 19, 2014 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.