Jump to content

PHP Navigation Trouble


talkingAnimals

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/162041-php-navigation-trouble/
Share on other sites

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.

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">

 

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.