talkingAnimals Posted June 13, 2009 Share Posted June 13, 2009 I'm having some trouble with a site that includes a simple PHP nav... The Page <?php $thisPage='contact';?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <link rel='stylesheet' href='generalstyles.css' type='text/css'/> </head> <body> <div id="page"> <div> <div id="headerimgz"> <div style="float:right; width:231px; height:138px; margin-right:15px;"><object width="231" height="138"><param name="movie" value="flash/headerFlash.swf"><embed src="flash/headerFlash.swf" width="231" height="138"></embed></object> </div> <div id="customNavz"> <?php include("includes/nav.php"); ?> </div> </div> </div> </body> </html> nav.php: <link rel="stylesheet" href="http://www.mindfully21.com/style.css" type="text/css" media="screen" /> <?php if($thisPage=='blog') {echo '<span class="current">blog</span>';} else {echo '<a href="blog.php">services</a>';}?> <?php if($thisPage=='services') {echo '<span class="current">services</span>';} else {echo '<a href="services.php">services</a>';}?> <?php if($thisPage=='about') {echo '<span class="current">about</span>';} else {echo '<a href="about.php">about</a>';}?> <?php if($thisPage=='contact') {echo '<span class="current">contact</span>';} else {echo '<a href="contact.php">contact</a>';}?> <?php if($thisPage=='policy') {echo '<span class="current">policy</span>';} else {echo '<a href="policy.php">policy</a>;';}?> The CSS just gives the text an underline. The nav shows up fine in the pages, it just doesn't seem to be catching on any of the conditionals. It always turns up the 'else' part. Even when it should absolutely turn up true... I've tried rewriting each bit and reworking pieces but I can't figure it out... It was working just fine a little while ago, but I must have done something weird that I keep over looking! Please help! Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/ Share on other sites More sharing options...
waynew Posted June 13, 2009 Share Posted June 13, 2009 If it's working on the else; then it's obviously failing on the other conditions. Could you please use the code tags? It makes it easier for us to read. Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855005 Share on other sites More sharing options...
MadTechie Posted June 13, 2009 Share Posted June 13, 2009 your nav.php page doesn't seam to have any closing php tags (?>) but lots of opening one! Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855009 Share on other sites More sharing options...
.josh Posted June 13, 2009 Share Posted June 13, 2009 so after you fix that, next question would be, what makes you think it is absolutely turning up true? Does $thisPage contain what you expect? echo it out? Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855018 Share on other sites More sharing options...
talkingAnimals Posted June 13, 2009 Author Share Posted June 13, 2009 Where else should I add the closing tags? Isn't the correct format <?php if(condition) {do this;} else {do this;} ?> IE: <?php if($thisPage=='blog') {echo '<span class="current">blog</span>';} else {echo '<a href="blog.php">blog</a>';} ?> I'm sure it's obvious that I'm very new at php! Also, I tried echoing out the #thisPage value and it comes up as expected. The live example is here: http://mindfully21.com/blog (the top nav is what I'm having trouble with... click through to contact, about etc.) Much Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855021 Share on other sites More sharing options...
MadTechie Posted June 13, 2009 Share Posted June 13, 2009 Okay lets echo it just before we use it <?php echo "*****'$thisPage'****"; if($thisPage=='blog'){ echo '<span class="current">blog</span>'; }else{ echo '<a href="blog.php">services</a>'; } if($thisPage=='services'){ echo '<span class="current">services</span>'; }else{ echo '<a href="services.php">services</a>'; } if($thisPage=='about'){ echo '<span class="current">about</span>'; }else{ echo '<a href="about.php">about</a>'; } if($thisPage=='contact'){ echo '<span class="current">contact</span>'; }else{ echo '<a href="contact.php">contact</a>'; } if($thisPage=='policy'){ echo '<span class="current">policy</span>'; }else{ echo '<a href="policy.php">policy</a>;'; } ?> Also from your live page <div class-"formShell"> should be <div class="formShell"> Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855026 Share on other sites More sharing options...
talkingAnimals Posted June 13, 2009 Author Share Posted June 13, 2009 OKAY! Now i guess I'm getting somewhere. THANKS! I put the echo in the page itself, not the php file... So when the $thispage is echoed, it turns up the $thispage of the nav.php file, not the page: http://www.mindfully21.com/contact.php That makes sense... the only thing is, I've used this method before and it turns up the $thispage value of the page the php file is included on, rather than the nav.php file. Also, it was working previously and just started not working... Any ideas? Any ideas? Or how do you get it to echo the $thispage value of the page, not the php file? Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855037 Share on other sites More sharing options...
MadTechie Posted June 13, 2009 Share Posted June 13, 2009 Okay first remove all of the $thisPage= (not from the IF's just anywhere your setting it then add this to the start of the blog.php, services.php etc etc etc <?php $thisPage=substr(basename(__FILE__), 0, -3);?> that will set $thisPage to blog or services etc etc etc Now when you include nav.php it will read $thisPage correctly Quote Link to comment https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/#findComment-855093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.