create cms page and static block programmatically in Magento


We can create by admin go to CMS menu -> create new Pages. Similarly, we can create Static Blocks, go to CMS menu -> create new Static Blocks.

In this code how to create CMS pages and Static blocks programmatically.


This code for Create CMS Page....
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$Page = array(
'title' => 'New Page',
'identifier' => 'new-page',
'content' => 'we can any content',
'is_active' => 1,
'sort_order' => 0,
'stores' => array(0),
'root_template' => 'three_columns'
);

Mage::getModel('cms/page')->setData($Page)->save();

This code for Create Static Block.....

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$Block = array(
'title' => 'New Block',
'identifier' => 'new-block',
'content' => 'we can any content',
'is_active' => 1,
'stores' => array(0)
);

Mage::getModel('cms/block')->setData($Block)->save();

Labels: