1

I would like to display a Wordpress Menu in the OpenCart Header. In my test.php page I added the following code;

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

And it works great, however when I add that into the header.tpl template in OpenCart I receive an error;

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

Can you assist? Have you done this before? Seems that OpenCart is causing the problem?

APPENDED UPDATE ON PROGRESS BELOW

Okay, I have run default installations of OC and WP.

Wordpress is in the root - www.test.local Opencart is in the root/store directory - www.test.local/store/

In the Opencart Default Tenplate Header I have the following code:

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

Which Generates the following error:

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

Interestingly though, when I delete the 'Test' Menu from Wordpress, the menu displays in Opencart, However I still see the following error:

/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

A clue? Anyone got any ideas?

Stuart
  • 690
  • 2
  • 9
  • 26
  • Not sure why WP is throwing the error, but it's not OC that's causing the issue – Jay Gilford May 15 '13 at 13:06
  • Maybe posting that part of the `header.tpl` could help us understand what may be causing the problem...? Speaking of `header.tpl` - do You include that wordpress files directly into the template? – shadyyx May 15 '13 at 13:30
  • 1
    You need more than that to declare an object within WordPress and you need to define your root for WordPress. This is hideous code and it is a bad idea to chuck in raw PHP like that within the .tpl of OpenCart. Plugin and logical MVC is better. I made a post on this. http://stackoverflow.com/questions/13208488/how-to-make-a-simple-module-in-opencart-example-getting-latest-posts-from-wordp – TheBlackBenzKid May 15 '13 at 15:01
  • 1
    @TheBlackBenzKid Very nice and extensive answer! – shadyyx May 15 '13 at 15:38
  • shadyyx - Don't think posting the header.tpl will help. TheBlackBenzKid, that is helpful, but it pulls the posts, I'm not to sure on amending for the menus. Jay - You are the man, always there and answering, but this time.... your hands tired? – Stuart May 16 '13 at 08:09
  • TheBlackBenzKid, that is helpful, but it pulls the posts, I'm not to sure on amending for the menus, I have just tested this in the header files (tpl/php), but get an error from one of the vqmods (Parse error: parse error in /......./vqmod/vqcache/vq2-catalog_controller_common_header.php on line 167). – Stuart May 16 '13 at 08:17

2 Answers2

1

i believe you would need to include the wp-blog-header.php not the wp-load take a look at this http://www.problogdesign.com/wordpress/use-wordpress-as-a-php-framework-for-your-static-html-pages/

  • Thanks for this. This is a pretty good post and article. It would be better to insert the article inside here with all the tags and actually do the mod and practice yourself and I am sure an answer is worth it. Good link +1 – TheBlackBenzKid May 16 '13 at 08:07
  • @Stuart have you define the menu in the functions.php file? have you installed wordpress prior to excute any code? – Leandro Villagran May 16 '13 at 17:26
  • The WP and OC installations work fine. store. for the OC installation and www. for the WP install, could that be the issue? How should I manually specify the menu in the WP functions file, it works in WP and in the store. site as a test.php file. I borks when it is put into one of the OC pages. – Stuart May 16 '13 at 20:23
  • you will need to register your menu on the functions.php file like this register_nav_menu('Test', 'Menu Label goes here'); also if you added the include('wp-blog-header.php') to your test.php you should be able to call bloginfo('title') and you should be able to see the your wordpress title so make sure that you can call other wordpress function – Leandro Villagran May 16 '13 at 21:09
  • Still the same error 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 – Stuart May 16 '13 at 21:22
  • $wp_query = $GLOBALS['wp_query']; add this to your functions.php it would help if you can show some of the code. – Leandro Villagran May 16 '13 at 21:31
0

The "Constant DB_PASSWORD already defined" is thrown because WP and OC use the same define variable for database password. You need to change the OC DB_PASSWORD variable name to DB_PASSWORD_OC, and then in index.php change the following:

// Database

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

to comply with the new variable name:

// Database

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

vladko13
  • 184
  • 1
  • 7