简体   繁体   中英

Magento: How can I add two or more static Blocks on category page

I am creating category page and i want to add two static blocks to it. While I was going through CMS/Static Blocks, I realized I can Only add One Static Block to any page. I couldn't find anything where i can add 2 or more static blocks. Is there a way i can add two or more such static blocks in a single category page.

If you want to add static block from Catalog->Manage Categories, then as you know you can call 1 static block at a time, but by using simple trick, you can call as many static blocks as you want.

类别

Call 1 static block from admin panel Catalog->Manage Categories. Then call other static blocks from static block, which you are calling from category.

静态块

I hope this will help you.

First add new field into category.I have create a new field name "landing_page_2". I have created and extension for that works...

Step1:Create config.xml Under: app\\code\\local\\Amit\\Catmattribute\\etc

<?xml version="1.0"?>
<config>
  <modules>
    <Amit_Catmattribute>
      <version>0.1.0</version>
    </Amit_Catmattribute>
  </modules>
  <global>
    <helpers>
      <catmattribute>
        <class>Amit_Catmattribute_Helper</class>
      </catmattribute>
    </helpers>
    <models>
      <catmattribute>
        <class>Amit_Catmattribute_Model</class>
        <resourceModel>catmattribute_mysql4</resourceModel>
      </catmattribute>
    </models>
    <resources>
      <categoryattribute1394603225_setup>
        <setup>
          <module>Amit_Catmattribute</module>
          <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </categoryattribute1394603225_setup>
      <categoryattribute1394603225_write>
        <connection>
          <use>core_write</use>
        </connection>
      </categoryattribute1394603225_write>
      <categoryattribute1394603225_read>
        <connection>
          <use>core_read</use>
        </connection>
      </categoryattribute1394603225_read>
    </resources>
  </global>
</config> 

step2:Create mysql4-install-0.1.0.php under:app\\code\\local\\Amit\\Catmattribute\\sql\\categoryattribute1394603225_setup

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("catalog_category", "landing_page_2",  array(
    "type"     => "int",
    "backend"  => "",
    "frontend" => "",
    "label"    => "CMS Block 2",
    "input"    => "select",
    "class"    => "",
    "source"   => "catalog/category_attribute_source_page",
    "global"   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'group'    => 'Display Settings',
    "visible"  => true,
    "required" => false,
    "user_defined"  => false,
    "default" => "",
    "searchable" => false,
    "filterable" => false,
    "comparable" => false,

    "visible_on_front"  => false,
    "unique"     => false,
    "note"       => ""

    ));
$installer->endSetup();

Step3:create Data.php

app\\code\\local\\Amit\\Catmattribute\\Helper

<?php
class Amit_Catmattribute_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Step4:Amit_Catmattribute.xml under app/etc/modules/

<?xml version="1.0"?>
<config>
  <modules>
    <Amit_Catmattribute>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Amit_Catmattribute>
  </modules>
</config>

Copy view.php from app/code/core/Mage/Catalog/Block/Category/

to app/code/local/Mage/Catalog/Block/Category/ add new function

public function getCmsBlocktwoHtml()
    {
        if (!$this->getData('cms_block_html_2')) {
            $html = $this->getLayout()->createBlock('cms/block')
                ->setBlockId($this->getCurrentCategory()->getLandingPage2())
                ->toHtml();
            $this->setData('cms_block_html_2', $html);
        }
        return $this->getData('cms_block_html_2');
    }

app\design\frontend\your package\your template\template\catalog\category\view.ptml
below code add after <?php echo $this->getCmsBlockHtml() ?>

<?php echo $this->getCmsBlocktwoHtml()?>

Hope it will be works.The section will manage fro madmin

You can put the following code in .phtml file to call static block

<?php $app = Mage::app(); ?>
<?php echo $app->getLayout()
->createBlock('cms/block')
->setBlockId('your_block_id')->toHtml(); ?> 

What you can do is create the two required static blocks from cms>static blocks (eg:st1 and st2) and an another static block that will include both these static blocks (eg: dual_block).

In the dual_block static block you can insert widget, choose widget type as CMS Static Block then select the required block. You can similarly add other blocks as well. Make the required formatting to display the blocks as required.

Then in the required category, click on display settings tabs, select display mode as static block only and in CMS Block select dual_block static block. Then save the category and now you have two static blocks displayed in the category page.

Hope it helps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM