There are following unique pages as category, product and cms pages.
Here, we will create an attribute for these pages as
1.CMS Page
<?php
$installer = $this;
$installer->startSetup();
$installer->run('
ALTER TABLE '. $this->getTable("cms_page") .
' ADD column seo_footer_cms_content text NULL;
');
$installer->endSetup();
?>
2.Category Page
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_category', 'seo_footer_category_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'SEO Footer Content',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => 0,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => '',
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'unique' => 0,
'position' => 1,
));
$installer->endSetup();
?>
3.Product page
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'seo_footer_product_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'SEO Footer Content',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => 0,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => '',
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'unique' => 0,
'position' => 1,
));
$installer->endSetup();
?>
Now you can see corresponding attribute of product and category in admin.
But for cms page we have to add following code (use adminhtml_cms_page_edit_tab_meta_prepare_form event). Lets add below code in config.xml
<adminhtml>
<events>
<adminhtml_cms_page_edit_tab_meta_prepare_form>
<observers>
<bd_cms_page_edit_tab_meta>
<type>singleton</type>
<class>Bd_Attributes_Model_Observer</class>
<method>createCMSAttribute</method>
</bd_cms_page_edit_tab_meta>
</observers>
</adminhtml_cms_page_edit_tab_meta_prepare_form>
</events>
</adminhtml>
now create createCMSAttribute function in Bd/Attribures/Model/Observer.php file
public function createCMSAttribue($observer)
{
$form = $observer->getEvent()->getForm();
$fieldset = $form->getElement('meta_fieldset');
$fieldset->addField('seo_footer_cms_conten', 'editor', array(
'name' => 'seo_footer_cms_content',
'label' => Mage::helper('cms')->__('SEO Footer Content'),
'title' => Mage::helper('cms')->__('SEO Footer Content'),
'style' => '',
'wysiwyg' => false,
'disabled' => 0
));
}
To show the content in the footer we need to add the following code in footer.phtml
<?php
$routeName=Mage::app()->getFrontController()->getRequest()->getRouteName();
$currentCategory = Mage::registry('current_category');
$currentProduct = Mage::registry('current_product');
if ($currentProduct):
echo $currentProduct->getSeoFooterProductContent();
elseif ($currentCategory):
echo $currentCategory->getSeoFooterCategoryContent();
elseif( $routeName == 'cms'):
$page = Mage::getSingleton('cms/page');
echo $page->getSeoFooterCmsContent();
endif;
?>
Here, we will create an attribute for these pages as
1.CMS Page
<?php
$installer = $this;
$installer->startSetup();
$installer->run('
ALTER TABLE '. $this->getTable("cms_page") .
' ADD column seo_footer_cms_content text NULL;
');
$installer->endSetup();
?>
2.Category Page
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_category', 'seo_footer_category_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'SEO Footer Content',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => 0,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => '',
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'unique' => 0,
'position' => 1,
));
$installer->endSetup();
?>
3.Product page
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'seo_footer_product_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'SEO Footer Content',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => 0,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => '',
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'unique' => 0,
'position' => 1,
));
$installer->endSetup();
?>
Now you can see corresponding attribute of product and category in admin.
But for cms page we have to add following code (use adminhtml_cms_page_edit_tab_meta_prepare_form event). Lets add below code in config.xml
<adminhtml>
<events>
<adminhtml_cms_page_edit_tab_meta_prepare_form>
<observers>
<bd_cms_page_edit_tab_meta>
<type>singleton</type>
<class>Bd_Attributes_Model_Observer</class>
<method>createCMSAttribute</method>
</bd_cms_page_edit_tab_meta>
</observers>
</adminhtml_cms_page_edit_tab_meta_prepare_form>
</events>
</adminhtml>
now create createCMSAttribute function in Bd/Attribures/Model/Observer.php file
public function createCMSAttribue($observer)
{
$form = $observer->getEvent()->getForm();
$fieldset = $form->getElement('meta_fieldset');
$fieldset->addField('seo_footer_cms_conten', 'editor', array(
'name' => 'seo_footer_cms_content',
'label' => Mage::helper('cms')->__('SEO Footer Content'),
'title' => Mage::helper('cms')->__('SEO Footer Content'),
'style' => '',
'wysiwyg' => false,
'disabled' => 0
));
}
To show the content in the footer we need to add the following code in footer.phtml
<?php
$routeName=Mage::app()->getFrontController()->getRequest()->getRouteName();
$currentCategory = Mage::registry('current_category');
$currentProduct = Mage::registry('current_product');
if ($currentProduct):
echo $currentProduct->getSeoFooterProductContent();
elseif ($currentCategory):
echo $currentCategory->getSeoFooterCategoryContent();
elseif( $routeName == 'cms'):
$page = Mage::getSingleton('cms/page');
echo $page->getSeoFooterCmsContent();
endif;
?>
Most of people using magento press release extension for content addition and I think this is the easy way to add content in your website header, body or footer portion. I am also preferring this extension for content addition.
ReplyDelete