Closed Thread Icon

Topic awaiting preservation: Quick Question for a dymanic navigation using PHP Pages that link to <a href="https://ozoneasylum.com/backlink?for=31516" title="Pages that link to Topic awaiting preservation: Quick Question for a dymanic navigation using PHP" rel="nofollow" >Topic awaiting preservation: Quick Question for a dymanic navigation using PHP\

 
Author Thread
Radical Rob
Paranoid (IV) Inmate

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

posted posted 12-05-2009 00:09

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>


Thanks!

papamike
Obsessive-Compulsive (I) Inmate

From: Southern USA
Insane since: Dec 2009

posted posted 12-05-2009 00:42
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)

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-05-2009 03:40

This is how I would do it :

Have a switch statement

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

etc....

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

etc....


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

Later,

C:\

« BackwardsOnwards »

Show Forum Drop Down Menu