Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Worpress Integration
 
jjafuller
Jr. Member
 
Total Posts:  17
Joined:  2008-03-24
 

So, we needed to achieve nodal content for CMS pages. So, basically what we did was setup wp to manage CMS page content via the following mechanism. It is fairly crude at this point, but it does work. I would like to get feedback on problems, or improvements.

---------------------------

1. Download WP - http://wordpress.org/download/

2. Extract WP in a ‘wp’ directory at root

3. Create wp-config.php with the following:

<?php

function get_magento_path($path)
{
  $backup 
= (strpos(getcwd(), 'wp-admin')) ? '../..' '..';
  
  return 
getcwd().'/'$backup '/' $path;
}

function parse_app_config($path null)
{
  $path 
= (empty($path)) ? get_magento_path('app/etc/local.xml') : $path;
  
  
$config = array();
  
  
$xml simplexml_load_file($pathnullLIBXML_NOCDATA);
    
  
$config['db'$xml->global->resources->default_setup->connection->dbname;
  
$config['un'$xml->global->resources->default_setup->connection->username;
  
$config['pw'$xml->global->resources->default_setup->connection->password;
  
$config['hp'$xml->global->resources->default_setup->connection->host;
  
  
$config['key'$xml->global->crypt->key;
  
  return 
$config;
}

$config 
parse_app_config();

// ** MySQL settings ** //
define('DB_NAME'$config['db']);    // The name of the database
define('DB_USER'$config['un']);     // Your MySQL username
define('DB_PASSWORD'$config['pw']); // ...and password
define('DB_HOST'$config['hp']);    // 99% chance you won't need to change this value
define('DB_CHARSET''utf8');
define('DB_COLLATE''');

// Change SECRET_KEY to a unique phrase.  You won't have to remember it later,
// so make it long and complicated.  You can visit https://www.grc.com/passwords.htm
// to get a phrase generated for you, or just make something up.
define('SECRET_KEY'$config['key']); // Change this to a unique phrase.

// You can have multiple installations in one database if you give each a unique prefix
$table_prefix  'wp_';   // Only numbers, letters, and underscores please!

// Change this to localize WordPress.  A corresponding MO file for the
// chosen language must be installed to wp-content/languages.
// For example, install de.mo to wp-content/languages and set WPLANG to 'de'
// to enable German language support.
define ('WPLANG''');

/* That's all, stop editing! Happy blogging. */

define('ABSPATH'dirname(__FILE__).'/');
require_once(
ABSPATH.'wp-settings.php');
?>

4. Finish installing WP

Direct browser to: http://example.com/wp/wp-admin.php

5. Set a permalink structure, it doesn’t matter, which just so we get clean urls enabled

6. Create all the categories you want to have available

7. Go to /wp/wp-content/themes/<yourtheme>/archive.php

* Remove all the calls to header, sidebar, and footer functions
* Remove anything that directly links to the post (that would take you out of the magneto environment
* Change the id of “content” to “wp-content” so it does not conflict with anything in magento

8. Create a new directory in your template: /app/design/frontend/<interface>/<theme>/template/wp/

9. Create block templates for each WP category in the folder you just created

In each block, paste the following. You should only need to change the category variable.

<?php

$category 
'home_en';

# shouln't need to change anything below this line

$secure = ($_SERVER['SERVER_PORT'== '443') ? true false;
$base_path Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,$secure);

$url $base_path.'wp/category/'.$category;

$ch curl_init();
curl_setopt($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_COOKIEJAR'cookie.txt');
curl_setopt($chCURLOPT_COOKIEFILE'cookie.txt');

$response curl_exec($ch);

if(
curl_errno($ch)) {
  $response 
= print curl_error($ch);
}

curl_close
($ch);

echo 
$response;

?>

10. Create pages using Magento’s CMS for each category, and insert the following as contents for each (replacing home_en with your category names):

{{block type="core/template" template="wp/home_en.phtml" name="home_en"}}

11. At this point you should be done. Viewing the pages should give you the full article listing structured by wordpress.

Limitations:

This method does not yet support the ability to have comments, or to view specific post entries.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sdb
Sr. Member
 
Avatar
Total Posts:  223
Joined:  2007-11-13
coastal California, USA
 

great smile
you should release a wordpress template that has all of those requirements built in already

it sounds like this keeps magento as a theme rather than using whatever wordpress theme there is, right?

 
Magento Community Magento Community
Magento Community
Magento Community
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

sounds great!! Need to try this and see. Would like to see more people sharing their views on this useful post.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sdb
Sr. Member
 
Avatar
Total Posts:  223
Joined:  2007-11-13
coastal California, USA
 

i thought of some of questions:
does post editing work? what about static pages? does the wordpress theme’s text styles (font color, size, etc) follow through into the magento pages?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ortsaipekim
Jr. Member
 
Total Posts:  18
Joined:  2007-11-07
 

I think this is a great post, congrats on getting this necessary bit done. I’d take a different approach, but it is specific to my situation, and may not apply to others:

1. I’d first concentrate on integrating the login/registration processes, so my users didn’t have to log in twice to post comments and track their order or whatever - inserting a row in the DB and setting some cookies on the magento login/logout and registration events.
2. I’d then probably just have wordpress include my Magento header/footer/shell template files - I’d do this, in my case, because my nav and footer links are static, and I don’t need any tighter integration like the one proposed in the post above. I would want to keep the magento and wordpress systems as “code-separate” as possible, but this may just be superstitious on my part.
3. I’d probably want to include ‘recent posts’ or something like that on my magento home page, so I’d call the magento xml-rpc server and have magento act as a client to get recent posts. Alternatively, I’d use the WP-on-a-Rope wordpress plugin to do this via SOAP.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jjafuller
Jr. Member
 
Total Posts:  17
Joined:  2008-03-24
 

Regarding Separate Logins: This is definitely a concern, I just needed a quick and dirty solution for the mean time

Regarding Themes: The goal is using wordpress to manage content, and create the basic html for it, but then have that wrapped in magento. That way I can have a consistent presentation layer rather than trying to create two templates that look the same

Regarding Static Page: You can accomplish the static pages but editing the php put into the custom block, just have it call the url for the static page instead of a category

Regarding releasing a premade set of templates: Until I figure out if there is a way to pass a variable in the CMS field of Magento, there is no other way to specific it other than created a unique template for each category

Regarding “Recent Posts”: This could easily be done tweaking the method above. You need only create a custom block that pulls the relevant block from wordpress.

 
Magento Community Magento Community
Magento Community
Magento Community
 
karynn
Member
 
Avatar
Total Posts:  70
Joined:  2008-02-07
 

Hm, I am trying this, but get the following error when I try to login to wp-admin:

Warningsimplexml_load_file() [function.simplexml-load-file]I/O warning failed to load external entity "shop/app/etc/local.xml" in /home/heritcom/public_html/wp-config.php on line 17

Warning
Cannot modify header information headers already sent by (output started at /home/heritcom/public_html/wp-config.php:17in /home/heritcom/public_html/wp-includes/pluggable.php on line 390
I have WordPress in my root directory (/home/heritcom/public_html) and Magento in a subdirectory /shop. I changed the PATH code in your example wp-config.php file to the following, perhaps it’s wrong?

//$path = (empty($path)) ? get_magento_path('shop/app/etc/local.xml') : $path;
  $path 'shop/app/etc/local.xml';

I then thought I needed a beginning “/” in the path to make it /shop/app/etc/local.xml, but when I did, I received this error when trying to reach the main WordPress site:

Warningsimplexml_load_file() [function.simplexml-load-file]I/O warning failed to load external entity "/shop/app/etc/local.xml" in /home/heritcom/public_html/wp-config.php on line 17

Any ideas?
Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jjafuller
Jr. Member
 
Total Posts:  17
Joined:  2008-03-24
 

My recommendation would be to change the “get_magento_path” function rather than trying to explicitly define a relative path:

function get_magento_path($path)
{
  $backup 
= (strpos(getcwd(), 'wp-admin')) ? '../..' '..';
  
  return 
getcwd().'/'$backup '/shop/' $path;
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Danielc1234
Sr. Member
 
Avatar
Total Posts:  175
Joined:  2008-01-09
Miami, FL - United States
 

jjafuller - Have you made any improvements on your initial integration? Like the ability to leave comments, etc?
And can you please list your URL so I can see it in action? We are interested in trying something like this.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rancs
Jr. Member
 
Total Posts:  1
Joined:  2008-05-15
 

Thanx for this great solution. I tried it and it’s working well for the jobs what it’s saying.

But i have some new important problems.

The first thing, wp isn’t integrated fully. When i go to http://siteurl/category/ i see the magento’s page. But when i go to http://siteurl/wp/category i arrive to wordpress page, not to magento’s. And search engines collect these wp links, and they send users to wordpress pages outside of magento (and my shop). If i make a redirection inside wordpress, the user come to wp page from search engine, redirecting to magento, come to wp page from mg, redirecting to mg, come from mg, redirecting mg… an infinite loop occurs.

The second one, this solution is very static. I have to create one magento cms pages for every wp page. If i integrate only category pages, i can make these cms pages. But if i want to integrate every single post, i have to create another cms page for everyone. This is impossible, i need a non-static method.

Could you show me a solution how to invoke magento instead of wordpress when a user come directly to http://siteurl/wp page? And a solution to a non-static integration formula?

Anyway, thanx for the solution, it’s really great.

 
Magento Community Magento Community
Magento Community
Magento Community
 
redb
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2008-02-15
Savoie, France
 

May be can you make a redirect in a .htaccess from your http://siteurl/wp to your http://siteurl/ url ? That what i will tried

regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
wired_mugen
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2008-07-15
Tagantog
 

Hello All.
I trying to integrate WP in Magento more deeper way.
I need to do autologin in wp when i login in magento. Any ideas?
wp(2.6)

 
Magento Community Magento Community
Magento Community
Magento Community
 
jia147003
Jr. Member
 
Total Posts:  1
Joined:  2011-05-23
 

<a href="http://www.oakleyshop.info/"><strong>OAKLEY</strong></a>—Classrooms were emptied in a hurry Monday when the Oakley outlet District reclaimed some of the space it had been leasing to a church.<br>
<a href="http://www.oakleyshop.info/"><strong>cheap oakley sunglasses</strong></a> at the oakleyshop.info that Mountain View Christian Center operates, at 5000 Amaryllis St., quickly had to redistribute students among the remaining <a href="http://www.oakleyshop.info/"><strong>oakley eyeglasses</strong></a> and the gymnasium after the school district began changing the locks, saying the church had reneged on the terms of its lease.<br>
"A deal is a deal," <a href="http://www.oakleyshop.info/versace-sunglasses-c-81.html"><strong>Versace sunglasses</strong></a> said in response to why the church couldn’t keep using the space given that the district doesn’t have immediate plans for it.<br>
--<a href="http://www.oakleyshop.info/ray-ban-sunglasses-c-77.html"><strong>ray ban sunglasses</strong></a>

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top