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.phprequire_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:- modifying an attributes set rises a JSON decoding error;
- editing a Layout Update causes a validation error;
- 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:- Conflict with __() function (I had prevented it by hacking Magento's function, but moving the line, I need to modify wp-l10n.php too);
- 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.
精彩评论