Topic: Quick Question for a dymanic navigation using PHP (Page 1 of 1) Pages that link to <a href="" title="Pages that link to Topic: Quick Question for a dymanic navigation using PHP (Page 1 of 1)" rel="nofollow" >Topic: Quick Question for a dymanic navigation using PHP <span class="small">(Page 1 of 1)</span>\

Radical Rob
Paranoid (IV) Inmate

From: Lost Angeles Kalifornia, via Hawaii....
Insane since: Jun 2001

IP logged posted posted 12-05-2009 00:09 Edit Quote

Hey guys,

This is usually my last resort when I get stuck on a problem and here I am, yet again, stuck.

I'm trying to use php to indicate the current page you are on by having a tab with white text while all others have blue.
I was thinking a simple if else type statement would work but I think I'm getting the syntax all wrong.

<div id="nav">

<?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?>

<a href="<img src="img/home_on.jpg" alt="Home" />

<a href="articles.php"> <?php if ($currentPage == 'index.php') {echo '<img src="img/articles_on.jpg"';} ?> <img src="img/articles_off.jpg" class="domroll img/articles_on.jpg" alt="Articles" /></a>

The logic seems simple enough to me. If $currentPage == 'index.php" then echo the on image. How do i impliment an else (display the off image)?
Does this make any sense? I'm sure there are a ton of easier ways to do this, one of which is not use images for the navigation.

<img src="img/gallery_off.jpg" class="domroll img/gallery_on.jpg" alt="Gallery" />
<img src="img/directory_off.jpg" class="domroll img/directory_on.jpg" alt="Directory" />
<img src="img/churches_off.jpg" class="domroll img/churches_on.jpg" alt="Churches" />
<img src="img/contact_off.jpg" class="domroll img/contact_on.jpg alt="Contact" /></div>
<div id="mainpic"></div>


Obsessive-Compulsive (I) Inmate

From: Southern USA
Insane since: Dec 2009

IP logged posted posted 12-05-2009 00:42 Edit Quote
<a href="<img src="img/home_on.jpg" alt="Home" />

Should be: <a href="link URL" title=""><img src="img/home_on.jpg" alt="home" /></a>

If all else fails, pull the plug!

(Edited by papamike on 12-05-2009 00:51)

Maniac (V) Inmate

Insane since: May 2001

IP logged posted posted 12-05-2009 03:40 Edit Quote

This is how I would do it :

Have a switch statement

switch ($_GET["page"]){
case gallery:
$body = "gallery";


I usually have something like this anyway. Makes it kind of like a template system. Just pulls the content based on the link anyway.

Then in the html of the page you can have

<body id="<?php echo $body; ?>">


Then for the link :
<a href="#" id="gallerypage">Gallery</a>

The ID has to be different that the body ID ;-)

Then in the CSS have :

body#gallery #gallerypage{
color:#fff; background: url(image_on.jpg);

This would make it so the background would change, so you could actually have the same background image for each different page.

Hope that makes sense. I've had a few beers



Post Reply
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
Your Text:
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu