<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Atwix &#187; wordpress</title>
	<atom:link href="http://www.atwix.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.atwix.com</link>
	<description>Custom Magento development, Magento modules and design</description>
	<lastBuildDate>Mon, 13 May 2013 10:28:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Integrating a WordPress blog with Magento</title>
		<link>http://www.atwix.com/magento/wordpress-magento/</link>
		<comments>http://www.atwix.com/magento/wordpress-magento/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:11:49 +0000</pubDate>
		<dc:creator>Volodymyr Vygovskyi</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[integrating]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.atwix.com/?p=774</guid>
		<description><![CDATA[There is no arguing the importance and effectiveness of a well structured and planned out blog on your site and WordPress is one of the easiest and most robust blog tools in the industry. So, how do you get this wonderful tool to work with your Magento store and help your SEO?]]></description>
				<content:encoded><![CDATA[<p>There is no arguing the importance and effectiveness of a well structured and planned out blog on your site and WordPress is one of the easiest and most robust blog tools in the industry. So, how do you get this wonderful tool to work with your Magento store and help your SEO?<span id="more-774"></span><br />
This post will painlessly teach you how to do so and how to integrate many other web applications.<br />
Integration can be done just in two steps:<br />
1. Using Magento&#8217;s header and footer.<br />
2. Matching Magento&#8217;s styles if needed.<br />
So, as an example we are integrating WordPress. First, you need to install it to your Magento&#8217;s directory. So here is our WordPress: magento_folder/blog.</p>
<p align="center"><a href="http://www.atwix.com/wp-content/uploads/2012/01/folder-strucure.png"><img class="aligncenter size-medium wp-image-804" src="http://www.atwix.com/wp-content/uploads/2012/01/folder-strucure-300x184.png" alt="Folder strucure, Magento-Wordpress" width="300" height="184" /></a></p>
<p>Next, we need to make Magento&#8217;s functions available for using in WordPress. </p>
<p>Some tweak required since there is an existing function collision between Magento and WordPress because both applications have an existing translator function named __():<br />
1. Copy <em>functions.php</em> from your Magento core folder <em>magento_folder/app/code/core/Mage/Core/</em> to <em>magento_folder/app/code/local/Mage/Core/</em>.<br />
2. Open it and find function <em>__()</em>.<br />
3. Replace </p>
<pre class="brush: php; gutter: true">
function __()
{
    return Mage::app()-&gt;getTranslator()-&gt;translate(func_get_args());
}
</pre>
<p>with </p>
<pre class="brush: php; gutter: true">
if (!function_exists(&#039;__&#039;)) {
	function __()
	{
		return Mage::app()-&gt;getTranslator()-&gt;translate(func_get_args());
	}
}
</pre>
<p></br></p>
<p>
There is a plugin, Mage Enabler that enables Magento&#8217;s session to run within WordPress. Install it and set absolute URL of the Mage.php file under plugin setting page:</p>
<p align="center"><a href="http://www.atwix.com/wp-content/uploads/2012/01/mage-path.png"><img src="http://www.atwix.com/wp-content/uploads/2012/01/mage-path-300x97.png" alt="mage path" width="300" height="97" class="aligncenter size-medium wp-image-808" /></a> </p>
<p>If you are integrating different application or can not use plugin, choose manual method by placing this PHP code to <em>header.php</em> file iside your active WordPress theme folder:</p>
<pre class="brush: php; gutter: true">
&lt;?php
$mage_php_url = &quot;/home/&lt;username&gt;/public_html/app/Mage.php&quot; //here is your Absolute URL of the Mage.php file	
if ( !empty( $mage_php_url ) &amp;&amp; file_exists( $mage_php_url ) &amp;&amp; !is_dir( $mage_php_url )) {
    // Include Magento&#039;s Mage.php file
    require_once ( $mage_php_url );
   	umask(0);
	Mage::app();
?&gt;	
</pre>
<p><br/><br />
Now it is time time to edit our <em>header.php</em>.<br />
This code creates Magento&#8217;s head, header blocks, place it to the top part of <em>header.php</em>:</p>
<pre class="brush: php; gutter: true">
$layout = Mage::getSingleton(&#039;core/layout&#039;);
// head block
$headBlock = $layout-&gt;createBlock(&#039;page/html_head&#039;);
// add JS
$headBlock-&gt;addJs(&#039;prototype/prototype.js&#039;);
$headBlock-&gt;addJs(&#039;lib/ccard.js&#039;);
$headBlock-&gt;addJs(&#039;prototype/validation.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/builder.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/effects.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/dragdrop.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/controls.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/slider.js&#039;);
$headBlock-&gt;addJs(&#039;varien/js.js&#039;);
$headBlock-&gt;addJs(&#039;varien/form.js&#039;);
$headBlock-&gt;addJs(&#039;varien/menu.js&#039;);
$headBlock-&gt;addJs(&#039;mage/translate.js&#039;);
$headBlock-&gt;addJs(&#039;mage/cookies.js&#039;);
// add CSS
$headBlock-&gt;addCss(&#039;css/styles.css&#039;);
$headBlock-&gt;getCssJsHtml();
$headBlock-&gt;getIncludes();
// header block
$headerBlock = $layout-&gt;createBlock(&#039;page/html_header&#039;)-&gt;setTemplate(&#039;page/html/header.phtml&#039;)-&gt;toHtml();
// footer block
$footerBlock = $layout-&gt;createBlock(&#039;page/html_footer&#039;)-&gt;setTemplate(&#039;page/html/footer.phtml&#039;)-&gt;toHtml();
// links block
$linksBlock = $layout-&gt;createBlock(&#039;page/template_links&#039;)-&gt;setTemplate(&#039;page/template/links.phtml&#039;)-&gt;toHtml();
</pre>
<p><b>Update.</b> Note that for <em>linksBlock</em> to show links inside <em>header</em> block you need to set it as child of header block and add links manually. So this part will looks like:</p>
<pre class="brush: php; gutter: true">
    $headerBlock = $layout-&gt;createBlock(&#039;page/html_header&#039;)-&gt;setTemplate(&#039;page/html/header.phtml&#039;);
    $linksBlock = $layout-&gt;createBlock(&#039;page/template_links&#039;)-&gt;setTemplate(&#039;page/template/links.phtml&#039;);
    $linksBlock-&gt;addLink(&#039;My Account&#039;,&#039;/customer/account/&#039;,&#039;My Account&#039;,&#039;&#039;,&#039;&#039;,10);
    $linksBlock-&gt;addLink(&#039;My Cart&#039;,&#039;/checkout/cart/&#039;,&#039;My Cart&#039;,&#039;&#039;,&#039;&#039;,10);
    $headerBlock-&gt;setChild(&#039;topLinks&#039;,$linksBlock);
    $headerBlock = $headerBlock-&gt;toHtml();
</pre>
<p>Insert head block into template, pasting following code after &lt;/title&gt; tag:</p>
<pre class="brush: php; gutter: true">
&lt;?php echo $headBlock-&gt;toHtml(); ?&gt;
</pre>
<p>Header block can be inserted after &lt;body&gt; tag, also we are going to insert template links block and navigation block. So here is an example of complete file:</p>
<pre class="brush: php; gutter: true">
&lt;?php
$layout = Mage::getSingleton(&#039;core/layout&#039;);
// head block
$headBlock = $layout-&gt;createBlock(&#039;page/html_head&#039;);
// add JS
$headBlock-&gt;addJs(&#039;prototype/prototype.js&#039;);
$headBlock-&gt;addJs(&#039;lib/ccard.js&#039;);
$headBlock-&gt;addJs(&#039;prototype/validation.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/builder.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/effects.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/dragdrop.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/controls.js&#039;);
$headBlock-&gt;addJs(&#039;scriptaculous/slider.js&#039;);
$headBlock-&gt;addJs(&#039;varien/js.js&#039;);
$headBlock-&gt;addJs(&#039;varien/form.js&#039;);
$headBlock-&gt;addJs(&#039;varien/menu.js&#039;);
$headBlock-&gt;addJs(&#039;mage/translate.js&#039;);
$headBlock-&gt;addJs(&#039;mage/cookies.js&#039;);
// add CSS
$headBlock-&gt;addCss(&#039;css/styles.css&#039;);
$headBlock-&gt;getCssJsHtml();
$headBlock-&gt;getIncludes();
// header block
$headerBlock = $layout-&gt;createBlock(&#039;page/html_header&#039;)-&gt;setTemplate(&#039;page/html/header.phtml&#039;)-&gt;toHtml();
// footer block
$footerBlock = $layout-&gt;createBlock(&#039;page/html_footer&#039;)-&gt;setTemplate(&#039;page/html/footer.phtml&#039;)-&gt;toHtml();
// links block
$linksBlock = $layout-&gt;createBlock(&#039;page/template_links&#039;)-&gt;setTemplate(&#039;page/template/links.phtml&#039;)-&gt;toHtml();
?&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?php
        global $page, $paged;
        wp_title( &#039;|&#039;, true, &#039;right&#039; );
        bloginfo( &#039;name&#039; );
        $site_description = get_bloginfo( &#039;description&#039;, &#039;display&#039; );
        if ( $site_description &amp;&amp; ( is_home() || is_front_page() ) )
            echo &quot; | $site_description&quot;;
        ?&gt;
    &lt;/title&gt;
    &lt;?php echo $headBlock-&gt;toHtml(); ?&gt;
    &lt;meta charset=&quot;&lt;?php bloginfo( &#039;charset&#039; ); ?&gt;&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; /&gt;
    &lt;link rel=&quot;profile&quot; href=&quot;http://gmpg.org/xfn/11&quot; /&gt;
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; href=&quot;&lt;?php bloginfo( &#039;stylesheet_url&#039; ); ?&gt;&quot; /&gt;
    &lt;link rel=&quot;pingback&quot; href=&quot;&lt;?php bloginfo( &#039;pingback_url&#039; ); ?&gt;&quot; /&gt;
    &lt;?php
        wp_head();
    ?&gt;
&lt;/head&gt;
&lt;body class=&quot; cms-index-index cms-home&quot;&gt;
    &lt;div class=&quot;wrapper&quot;&gt;
        &lt;div class=&quot;page&quot;&gt;
            &lt;?php
                echo $headerBlock;
                echo $linksBlock;
                $navBlock = $layout-&gt;createBlock(&#039;catalog/navigation&#039;)-&gt;setTemplate(&#039;catalog/navigation/top.phtml&#039;)-&gt;toHtml();
                echo $navBlock;
            ?&gt;
            &lt;div class=&quot;main-container&quot;&gt;
                &lt;div class=&quot;main&quot;&gt;
</pre>
<p>Next, edit <em>footer.php</em>.<br />
Use this code to insert footer block:</p>
<pre class="brush: php; gutter: true">
&lt;?php
        $layout = Mage::getSingleton(&#039;core/layout&#039;);
        $footerBlock = $layout-&gt;createBlock(&#039;page/html_footer&#039;)-&gt;setTemplate(&#039;page/html/footer.phtml&#039;)-&gt;toHtml();
        echo $footerBlock;
        ?&gt;
</pre>
<p>Complete footer.php file can look like this:</p>
<pre class="brush: php; gutter: true">
	&lt;/div&gt;&lt;!-- main --&gt;
    &lt;/div&gt;&lt;!-- main container --&gt;
        &lt;?php
            $layout = Mage::getSingleton(&#039;core/layout&#039;);
            $footerBlock = $layout-&gt;createBlock(&#039;page/html_footer&#039;)-&gt;setTemplate(&#039;page/html/footer.phtml&#039;)-&gt;toHtml();
            echo $footerBlock;
        ?&gt;
    &lt;/div&gt;&lt;!-- page --&gt;
&lt;/div&gt;&lt;!-- wrapper --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The last task is to edit CSS styles to match your Magento theme.<br />
Lets see what we’ve got.</p>
<p align="center"><a href="http://www.atwix.com/wp-content/uploads/2012/01/final-page.png"><img src="http://www.atwix.com/wp-content/uploads/2012/01/final-page-300x232.png" alt="Final page" title="Final page" width="300" height="232" class="aligncenter size-medium wp-image-827" /></a></p>
<p>Happy integrating!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.atwix.com/magento/wordpress-magento/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
