Magento Category Display Settings – How to Get CMS Block Value

categorycollection;selection

in the manage category page I have cms block which I want to update it programatically
I guess that the attribute id to set for this is landing_page

unfortunatley I don't know the function to get the landing page or get the cms block value

for example in this case Category Listing
how can I get that by collection?

$category = Mage::getModel('catalog/category')->load(17048);

also

echo $cat->getAttributeText('landing_page');

it doesn't show me anything

fortunately I did this!:

echo $cat->getlanding_page();

enter image description here

fortunately I solved part of the problem:

<?php include '/var/www/lenmar/mage_classes.php';?>
<?php $_helper = Mage::helper('catalog/category'); 
$cat = Mage::getModel('catalog/category')->load(17048);
$cat->setlanding_page('11');
$cat->save();
?>

so I can set it and show that but how I can get the value for that? I mean instead of Id I want to get Category Listing value

Best Answer

Use this code to retrieve cms block details

$cat = Mage::getModel('catalog/category')->load(13);

$mode  = $cat->getDisplayMode();
//display mode = PAGE means, that category has a static block
if($mode == 'PAGE' || $mode == 'PAGE_AND_PRODUCTS'){
    //get static block id
    $page = $cat->getLandingPage();

    //cms block
    $cms_block = Mage::getModel('cms/block')->load($page);

    //retrieve cms block data
    $title = $cms_block->getTitle(); // title of cms block
    $identifier = $cms_block->getIdentifier(); //identifier for that cms block
    $content = $cms_block->getContent(); //get entire content of cms block

    $content_data= $this->getLayout()->createBlock('cms/block')->setBlockId($cms_block->getIdentifier())->toHtml(); // if you are using shortcodes/variables in static block.
}

The key point here is, the method getLandingPage() provides cms block id. Using this block id, we are then load cms block model and retrieves appropriate blocks information.

Hope that helps

Related Topic