admin管理员组文章数量:1321812
I wanted to use WordPress menu management then show it on outside wordpress installion php file with html but I got this error
PHP Fatal error: Call to a member function get_queried_object() on a non-object in .../blog/wp-includes/nav-menu-template.php on line 395
Here how I do it in on php file with test.php
<?php
$documentroot = $_SERVER['DOCUMENT_ROOT'];
include_once($documentroot.'/blog/wp-load.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<div id="header">
<div id="main-nav">
<?php if ( has_nav_menu( 'landingpage-menu' ) ) { /* if menu location 'secondary-menu' exists then use custom menu */ ?>
<?php wp_nav_menu( array( 'theme_location' => 'landingpage-menu', 'container' => '', 'depth' => 1 ) ); ?>
<?php } ?>
</div>
</div>
</body>
</html>
is there wrong on how I implement it? or I'm missing something?
I wanted to use WordPress menu management then show it on outside wordpress installion php file with html but I got this error
PHP Fatal error: Call to a member function get_queried_object() on a non-object in .../blog/wp-includes/nav-menu-template.php on line 395
Here how I do it in on php file with test.php
<?php
$documentroot = $_SERVER['DOCUMENT_ROOT'];
include_once($documentroot.'/blog/wp-load.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<div id="header">
<div id="main-nav">
<?php if ( has_nav_menu( 'landingpage-menu' ) ) { /* if menu location 'secondary-menu' exists then use custom menu */ ?>
<?php wp_nav_menu( array( 'theme_location' => 'landingpage-menu', 'container' => '', 'depth' => 1 ) ); ?>
<?php } ?>
</div>
</div>
</body>
</html>
is there wrong on how I implement it? or I'm missing something?
Share Improve this question asked Jan 15, 2014 at 1:42 GeraldGerald 613 silver badges8 bronze badges2 Answers
Reset to default 1You can use this code and it will really help you a lot
<?php
require( '../wp-load.php' );
get_header(newtheme);
echo 'new content outside WordPress';
get_footer();
?>
That should work fine. Likely problems are either the incorrect path[1] at the top or no menu named landingpage-menu
[2].
[1] For the pathing, try this at the top of your file and see if it's doing what you expect.
<?php
$documentroot = $_SERVER['DOCUMENT_ROOT'];
echo "documentroot is: " . $documentroot . "<br><br>";
$filecontents = file_get_contents($documentroot.'/blog/wp-load.php');
echo $filecontents;
?>
[2] For the menus, try this:
<h2>Menu Locations</h2>
<pre>
<?php print_r($menuLocations); ?>
</pre>
<h2>Menus</h2>
<pre>
<?php print_r($menus); ?>
</pre>
It should list out all menus and menu locations.
本文标签: pluginswpnavmenu() Outside WordPress installation
版权声明:本文标题:plugins - wp_nav_menu(); Outside WordPress installation 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742098717a2420702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论