jcadima
4/22/2016 - 9:55 PM

Custom Static Block Loop - Get data from static Blocks

Custom Static Block Loop - Get data from static Blocks

http://stackoverflow.com/questions/9233133/magento-how-do-you-return-results-of-unlimited-cms-static-blocks-with-certain
<?php
/*
(1) this is the code where we get the static blocks collection based on 'testimonial'
/cendo/ma_cendo1/template/testimonialscustom/testimonialscustom.phtml
*/
<?php
    // add the collection with filters
$collection = Mage::getModel('cms/block')->getCollection()
    ->addFieldToFilter('identifier', array('like'=>'testimonial'.'%'))
    ->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 = $this->getIdentifier();
    $block_ID = $_blockId . $blockNum;
   //  echo "Key: " . $key . " - " . "Block ID: " . $block_ID . "<br >"; testing
    $blockNum++;    

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

    if ($_block) : ?>
        <div class="block2 block-testimonial2">
            <div class="block-title2">
                <strong><?php echo $this->getTitle(); ?></strong>
            </div>
        <div class="block-content2">
        <?php echo $_block->toHtml(); ?>
        </div>
    <?php 
    endif;
}





/*
(2)this is the custom template
/cendo/ma_cendo1/template/page/1column-testimonials.phtml
*/
create this template


/*
(3) This goes in the testimonials page which calls the data retrieved from (1)
*/
{{block type="core/template" template="testimonialscustom/testimonialscustom.phtml" title="" identifier="testimonial-"}}