Magento 1.9 – Create a archive of cms block

November 9th, 2016
  • First, you need to add a new template to the CMS page you want to use as archive. ( Magento 1.9 – add custom template to a CMS Page )
  • Open the template.phtml and after the closing of ” <div class=”main-container col1-layout”> ” add:

<!– Retrive the “logoscheda” static blocks –>
<?php
$collection = Mage::getModel(‘cms/block’)->getCollection()
->addFieldToFilter(‘identifier’, array(‘like’=>’logoscheda’.’%’))
->addFieldToFilter(‘is_active’, 1);

// get the count
$blockCount = $collection->count();
//echo ‘Block Count: ‘ . $blockCount . ‘<br />’; // just for testing

$blockNum = 1;
foreach($collection as $key => $value){
$_blockId = ‘logoscheda_’;
$block_ID = $_blockId . $blockNum;
//echo “Key: ” . $key . ” – ” . “Block ID: ” . $block_ID . “<br />”;
$blockNum++;

$_block = $this->getLayout()->createBlock(‘cms/block’)->setBlockId($block_ID);

if ($_block) : ?>
<div class=”block block-testimonial”>
<div class=”block-title”>
<strong><?php echo $this->getTitle(); ?></strong>
</div>
<div class=”block-content”>
<?php echo $_block->toHtml(); ?>
</div>
</div>
<?php endif; } ?>

<!– End logoscheda static bocks –>

  • Upload the .phtml file
  • Back in editor, and create 2 Static Blocks, as title you can write everything you want.
  • Important thing is that as id use “logoscheda_” + a consequential number.
  • Go to see archive page in frontend, you can see, the preview of Static Blocks.