Integrating Magento Header and Footer

Blogs have paramount importance to make websites especially for the Magento Developed Online Store using Magento 2 Development Services. Blogs provide better traffic and are a prime source of SEO leads. In this tough race comprising of Blogging Platforms, WordPress has turned out to be the fastest means of constructing these sites.

WordPress has the best platform to show Blogs with a Case Study you can certainly follow. Now if you wish to combine superiority of WordPress with Magento Store then an article serves as a perfect solution to the apparent problem.

How to Pull the Magento Header and Footer

Here we talk in detail how to integrate your Magento Header and Footer in a WordPress site. We are considering WordPress code within a folder named "blog" inside your Magento project you made.

[php]$str = dirname(__FILE__);
$basedir = substr($str, 0, strpos($str, 'blog'));
$mage_php_url = $basedir . 'app/Mage.php';
// Include Magento application
if (!empty($mage_php_url) && file_exists($mage_php_url) && !is_dir($mage_php_url)) {
// Include Magento's Mage.php file
require_once ( $mage_php_url );
umask(0);
Mage::app();
[/php]

After this, you can use Magento code in your WordPress code.

[php]$url = Mage::getBaseUrl();
$url = substr($url, 0, strpos($url, 'index.php'));
// skin url of magento
$skinUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
//js url
$jsUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);[/php]
This will provide you with the Magento url, Skin url and js url.
Include Magento session so that customer and checkout session will be maintained in it.

[php]Mage::getSingleton('core/session', array('name'=>'frontend'));[/php]

After inserting this line if the user logs into Magento shows him or her as logged into Word Press as well. Cart header shows an update of cart items as well. See the inclusion time with use of js and css files. Add all js and css files of Magento and get the style and functionality of Magento.

[php]<link rel="stylesheet" type="text/css" href="<?php echo $skinUrl . 
'frontend/default/default/css/styles.css'?>" media="all" />
<script type="text/javascript" src="<?php echo $jsUrl .'prototype/prototype.js'?>"></script>[/php]

In similar ways, you can include other files as well.

How to Add Custom Header and Footer
The Header
[php]$_layout = Mage::getSingleton('core/layout');
$block_header = $_layout->createBlock('page/html_header')-
>setTemplate('page/html/header.phtml');[/php]

This includes the header.phtm files.

Top Menu

[php]$block_Menu = $_layout->createBlock('page/html_topmenu', 'catalog.topnav')-
>setTemplate('page/html/topmenu.phtml');
$block_header->setChild('topMenu', $block_Menu);[/php]

Likewise, include another needed block

Top Links

[php]$block_links = $_layout->createBlock('page/template_links', 'top.links')->setTemplate('page/template/links.phtml');
$block_header->setChild('topLinks', $block_links);
$block_links->addLink('Home', $url . '', 'Home','', '', 10,'', 'class="top-link-home"');
$block_links->addLink('Account', $url . 'customer/account/', 'Account', '', '', 10,'','class="top-link-account"');
$block_links->addLink('Shopping Cart', $url . 'checkout/cart/', 'Shopping Cart', '', '', 10,'','class="top-link-cart"');
$block_links->addLink('Checkout', $url . 'checkout/onepage/', 'Checkout', '', '', 10,'','class="top-link-checkout"');[/php]

New Call to action:

It includes Home, Account, Cart and Checkout link on the header. The other link adds on similarly.

[php]echo $block_header->toHtml();[/php]

This shows the header html file.

Footer:

[php] $layout = Mage::getSingleton('core/layout');
$footerBlock = $layout->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml');
$news_subscribe = $layout->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml');
$footerBlock->setChild('newsletter', $news_subscribe);
echo $footerBlock->toHtml();[/php]


This includes footer.phtml file naming it; ‘Newsletter’ shows inside the footer. I can say with good amount of certainty that an article helps you to include Magento style on your WordPress site.

Comments

Popular posts from this blog

Add Business Benefits Using Marketing Strategies of Magento 2

Appearance and Usability in Website Designing

Web Designing Tools For Startups