0

I am attempting to change my menus depending upon the url. I have tried a couple of different things to no avail.

I have tried using php to call to the code on the page, (see the code below, I used this but rather than calling to the include file I was calling to the code itself on the page) and the result was a blank page in the browser.

Then I tried calling to the include files that I created with the menu code in it.

The menu itself, has some PHP in it and I think this may be why it is not working. I tried a simple call to the menu include file and the menu did not print out to the browser.

<?php include("/wp-content/themes/wslh/inc/i_menu-wohl.php"); ?>

It stopped printing out as soon as the menu php started, so when I did a view source there was only this:

<ul id="nav">
<li><a 

The php that came after that was:

<?php nav_active( 'about' ); ?> href="/about/">ABOUT<br>WSLH</a>

And the rest of the menu code, which is really long so I will not put it here. The menu itself works fine hard coded on the page when I am not trying to include it for this if then statement:

<?php
$url = $_SERVER["REQUEST_URI"];
if (strpos($url, "/occupational/wohl/") === 0) {
echo '<?php include("/wp-content/themes/wslh/inc/i_menu-wohl.php"); ?>';
} else {
echo '<?php include("/wp-content/themes/wslh/inc/i_menu-wslh.php"); ?>';
}
?>

Can anyone assist me with this? I have created if then else statements using ASP and have never run into this issue. Thank you in advance for your help. Please let me know if you have any questions or I have not given enough info.

JHP
  • 121
  • 3
  • 12
  • 1
    are you including the wp libraries in that file you're generating? you'er trying to generate PHP code on the fly, meaning you have to generate EVERYTHING , including the appropriate `include()`/`require()` directives so that nav_active() is actually defined when the generated code executes. – Marc B Oct 21 '13 at 20:58
  • @Marc B, this may be the issue, but I am not sure how to do it. What I was thought was that I could simply bring the menu code into the page using the include and that it would work because all that is different is that the menu code will change a little depending on which one is brought in via include. Looking at the header, I am not sure what I should be adding to the menu include file. I imagine what I am trying to do is probably quite simple, I just do not have the PHP experience yet. – JHP Oct 22 '13 at 14:26

1 Answers1

0

Firstly, this code will not do anything useful:

echo '<?php include("/wp-content/themes/wslh/inc/i_menu-wohl.php"); ?>';

What that will do is echo, to the browser, a string of PHP code. The browser won't know what to do with it.

All you actually need is to include the PHP file itself, like this:

include "/wp-content/themes/wslh/inc/i_menu-wohl.php";

(Note: I've removed the brackets, because include is not actually a function, and it can lead to bugs if you start thinking of it as one.)

Next, if the output is suddenly stopping where some PHP code is trying to run, you're probably getting an error, but have errors set to be logged rather than display.

Check out this answer and the other information on that page to help track down what the error was. If you're still stuck after that, post a new question, with the part of the code that produces the error and the exact error message it produces.

Community
  • 1
  • 1
IMSoP
  • 89,526
  • 13
  • 117
  • 169