开发者

Integrate Wordpress into Magento: problem including blog-header

开发者 https://www.devze.com 2023-03-20 03:22 出处:网络
I need to integrate my Magento site with several Wordpress resources. Since they are not just blog feed, I couldn\'t use a module or a rss block.

I need to integrate my Magento site with several Wordpress resources.

Since they are not just blog feed, I couldn't use a module or a rss block.

I found the best solution was including Wordpress header into Magento, and than call WP functions straight inside my blocks.

This is the magic line put on the top of Mage.php

require_once($_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-blog-header.php');

Everything works fine, except that I have a lot of problems with AJAX now.

Some examples:

  1. modifying an attributes set rises a JSON decoding error;
  2. editing a Layout Update causes a validation error;
  3. connecting to Magento Connect, cause 开发者_运维知识库the site looks for wp-install.php.

All these errors disappear if i commented out the require_once line.

Did anyone face the same problem?

Any suggestion on how to include the line just for the homepage?

I've tried to move the line to another position, but it raise a conflict, so I have to leave it on the top of the file.

UPDATE:

I've tried to put the line in other places (index.php or template files), but I get two errors:

  1. Conflict with __() function (I had prevented it by hacking Magento's function, but moving the line, I need to modify wp-l10n.php too);
  2. Every time I try to visit a page, the site redirect me to wp-install.


You should not be doing this for both the front and backend. Consider putting the include in your theme header.phtml file.

If you want it just for your homepage, add another theme to Magento and set the CMS for the homepage to use that. The theme can include nothing more than the header.phtml file, it will revert to the site theme defaults for everything else.


Make the wordpress content available on a separate URL then sub-request it from your block.

readfile($_SERVER['HTTP_HOST'].'/wordpress/wp-blog-header.php');
// ...or whatever the URL is

Perhaps you can access the wordpress data as JSON or XML with a sub-request and then format it within your block.

The point is the wordpress and magento requests are separate processes and so do not conflict with each other's namespace.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号