Forum Moderators: coopster
<? $navlocation = 'page';?>
where page is a name for whatever page I'm on. So if it's the home page, for instance, I put
<? $navlocation = 'home';?>
So the idea here is, if it's the home page, display a static image; otherwise, display the rollover image.
To accomplish this, I have created a menu.php file that has all the site's navigation with if/else statements; I am including this on all the pages in the site. Here's what the code for the home page link looks like:
<? if($navlocation == 'home') {?>
<img src="images/home-inactive.jpg" alt="Home" width="195" height="36" border="0" />
<? } else {?>
<a href="http://www.somesite.com/"
onmouseover="changeImages('home', 'images/home-over.jpg'); return true;"
onmouseout="changeImages('home', 'images/home.jpg'); return true;"><img src="images/home.jpg" alt="Home" name="home" width="195" height="36" border="0" id="home" /></a>
<? }?>
Unfortunately, this doesn't work. If I put the string <? $navlocation = 'home';?> in the menu.php file it works fine, but that negates the whole point.
So what am I doing wrong here?
A while back I did this sort of thing a different way where the if/else statements were focused on the actual file path and directories involved, but I've forgotten what the right string is for that.
I'd really appreciate some help with this!
[edited by: dreamcatcher at 11:58 am (utc) on Aug. 18, 2006]
[edit reason]
[1][edit reason] No urls as per TOS [webmasterworld.com] Thanks. [/edit] [/edit][/1]
In your included menu.php page, what happens if you put the line echo $navlocation?
So I tried your suggestion in a couple of ways...
first I tried putting
<? echo $navlocation;?>
at the top of the menu.php file.
Then I tried adding it right before the if statement:
<? echo $navlocation; if($navlocation == 'home') {?>
I don't know much about PHP, really, so I could have done that wrong too... but neither way worked... thanks for replying, though. Do I need to go about this a different way?
I put
<? echo $navlocation;?>
in the actual html file, which is what contains the variable, to see if it would work and it didn't!
Is there something wrong with this?
<? $navlocation = 'home';?>
Does it need to go in a specific point on the page, or can it go anywhere before the include? I've tried it in all kinds of places (the top of the page before the head, just after the body tag, and in the same table cell as the include) and it doesn't seem to make a difference.
The include works fine:
<? include 'menu.php'?>
I also tried
<? $navlocation = 'home';
include 'menu.php'?>
but the results were the same. It just seems like the navlocation variable string is being completely ignored, but I can't figure out why. This is in an HTML file; I added a MIME type so the server knows to parse HTML files for PHP, and like I said, the include works fine. I'm so confused!
<?php
$navlocation = 'home';
echo 'NAVLOCATION: '.$navlocation;
?>
And see if your $navlocation gets echoed out.
Also, just a FYI: It's generally better to use the full <?php opening tag rather than the shorthand <? one -- that shorthand one doesn't work on all servers, and if you ever do any xhtml page it can much up the doctype.
First I tried:
<?php
$navlocation = 'home';
echo 'NAVLOCATION: '.$navlocation;
?>
and this caused, as expected,
navlocation: home
to appear at the top of the page.
So next I tried this:
<?php $navlocation = 'home';?>
<?php include 'http://www.somesite.com/menu.php';?>
Then put this in the menu.php file:
<?php echo 'navlocation: '.$navlocation;?>
<?php if($navlocation == 'home') {?>
<img src="http://www.somesite.com/images/home-inactive.jpg" alt="Home" width="195" height="36" border="0" />
<?php } else {?>
<a href="http://www.somesite.com/"
onmouseover="changeImages('home', 'http://www.somesite.com/images/home-over.jpg'); return true;"
onmouseout="changeImages('home', 'http://www.somesite.com/images/home.jpg'); return true;">
<img src="http://www.somesite.com/images/home.jpg" alt="Home" name="home" width="195" height="36" border="0" id="home" /></a>
<?php }?>
When I did that, the navlocation did NOT echo. I got:
navlocation:
Why would this be? I'm so confused.
[edited by: dreamcatcher at 6:30 am (utc) on Aug. 26, 2006]
[edit reason]
[1][edit reason] No urls as per TOS [webmasterworld.com] Thanks. [/edit] [/edit][/1]