1

我想在 OpenCart 标题中显示一个 Wordpress 菜单。在我的 test.php 页面中,我添加了以下代码;

<?php
require($_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-load.php');  
wp_nav_menu( array( 'menu' => 'Test' ) ); ?>

而且效果很好,但是当我将其添加到 OpenCart 的 header.tpl 模板中时,我收到一个错误;

Fatal error: Call to a member function get_queried_object() on a non-object in /....../wordpress/wp-includes/nav-menu-template.php on line 256

你能帮忙吗?你以前做过吗?似乎是 OpenCart 导致了问题?

以下是关于进展的附加更新

好的,我已经运行了 OC 和 WP 的默认安装。

Wordpress 位于根目录中 - www.test.local Opencart 位于根目录/存储目录中 - www.test.local/store/

在 Opencart Default Tenplate Header 中,我有以下代码:

<?php $path = $_SERVER['DOCUMENT_ROOT'].'/wp-load.php';
      echo $path;
      require_once($path);  
      wp_nav_menu( array( 'menu' => 'Test' ) ); ?>

这会产生以下错误:

test.local/Sites/test.local/htdocs/wp-load.phpNotice: Constant DB_PASSWORD already defined in test.local/Sites/test.local/htdocs/wp-config.php on line 25Unknown: Redefining already defined constructor for class WP_Widget in test.local/Sites/test.local/htdocs/wp-includes/widgets.php on line 93Warning: strpos() expects parameter 1 to be string, array given in test.local/Sites/test.local/htdocs/wp-includes/functions.php on line 3048
Fatal error: Call to a member function get_queried_object() on a non-object in test.local/Sites/test.local/htdocs/wp-includes/nav-menu-template.php on line 256

有趣的是,当我从 Wordpress 中删除“测试”菜单时,菜单显示在 Opencart 中,但是我仍然看到以下错误:

/Sites/test.local/htdocs/wp-load.phpNotice: Constant DB_PASSWORD already defined in /Sites/test.local/htdocs/wp-config.php on line 25Unknown: Redefining already defined constructor for class WP_Widget in /Sites/test.local/htdocs/wp-includes/widgets.php on line 93Warning: strpos() expects parameter 1 to be string, array given in /Sites/test.local/htdocs/wp-includes/functions.php on line 3048Notice: Trying to get property of non-object in /Sites/test.local/htdocs/wp-includes/post-template.php on line 845

线索?有人有什么想法吗?

4

2 回答 2

1

我相信你需要包括 wp-blog-header.php 而不是 wp-load 看看这个 http://www.problogdesign.com/wordpress/use-wordpress-as-a-php-framework-for -你的静态html页面/

于 2013-05-15T19:43:09.413 回答
0

抛出“Constant DB_PASSWORD already defined”是因为 WP 和 OC 使用相同的数据库密码定义变量。您需要将 OC DB_PASSWORD 变量名称更改为 DB_PASSWORD_OC,然后在 index.php 中更改以下内容:

// 数据库

$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); ...

遵守新的变量名:

// 数据库

$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD_OC, DB_DATABASE);

于 2015-01-13T11:45:56.573 回答