将 Wordpress 集成到 Magento:包括博客标题的问题

发布于 2024-11-19 13:41:10 字数 752 浏览 2 评论 0原文

我需要将我的 Magento 网站与多个 Wordpress 资源集成。
由于它们不仅仅是博客提要,因此我无法使用模块或 rss 块。
我发现最好的解决方案是将 Wordpress 标头包含到 Magento 中,然后直接在我的块内调用 WP 函数。
这是放在 Mage.php 顶部的魔法线,

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

一切正常,除了我现在 AJAX 有很多问题。
一些示例:

  1. 修改属性集会引发 JSON 解码错误;
  2. 编辑布局更新会导致验证错误;
  3. 连接到 Magento Connect,因为该站点会查找 wp-install.php。

如果我注释掉 require_once 行,所有这些错误都会消失。
有人遇到同样的问题吗?
关于如何仅在主页中包含该行有什么建议吗?
我尝试将该行移至另一个位置,但它引发了冲突,因此我必须将其保留在文件顶部。

更新:
我尝试将该行放在其他地方(index.php 或模板文件),但出现两个错误:

  1. 与 __() 函数冲突(我通过破解 Magento 的函数来阻止它,但是移动该行,我需要也修改 wp-l10n.php);
  2. 每次我尝试访问某个页面时,该网站都会将我重定向到 wp-install。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城烟雨 2024-11-26 13:41:10

您不应该对前端和后端都这样做。考虑将包含内容放入主题 header.phtml 文件中。

如果您只想将其用于主页,请向 Magento 添加另一个主题,并将主页的 CMS 设置为使用该主题。主题只能包含 header.phtml 文件,其他所有内容都会恢复为站点主题默认值。

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.

時窥 2024-11-26 13:41:10

让 WordPress 内容在单独的 URL 上可用,然后从您的块中对其进行子请求。

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

也许您可以使用子请求以 JSON 或 XML 形式访问 WordPress 数据,然后在块中对其进行格式化。

关键是 wordpress 和 magento 请求是单独的进程,因此不会与彼此的名称空间冲突。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文