ok heres one for you, php include

Joined
12 Feb 2006
Posts
17,625
Location
Surrey
ok so i can do php include and all that, but i would like to know, is when say including the navigation links, on the page i currently am on i tend to have it a differnet looking button/link as much places, but how would i do that with php include?

like with latest site i made, navButtonOn (current page), and navButtonOff (all other pages), how would i say include nav.html, then change contact navigation button to be on etc?
 
If it's a smaller site, I'd just use body IDs and CSS.

Code:
ul#mainNav li a {background:url('defaultBg.jpg');} 
body#about ul#mainNav li#about a {background:url('currentBg.jpg');

The above would use defaultBg unless both the body and list item have an ID of 'about'.

Also, if you're using mouseovers for your navigation, you're best off putting the three images together (default, hover and currentPage) and then just shifting the background. Because the full image will load on pageload, you won't get any flashes or delays when you mouseover and it also keeps things more tidy IMO.
 
Last edited:
Have php in your include to check current location and output the HTML accordingly :)

if im reading what you have said correclty not really sure how that would work with what i have done.

this is roughly what i have,

Code:
<div id="navButtonOff"><a href="index.html">Home</a></div>
<div id="navButtonOff"><a href="about.html">Home</a></div>
<div id="navButtonOff"><a href="services.html">Home</a></div>
<div id="navButtonOff"><a href="contact.html">Home</a></div>
so how would the php check say ok we are on index.html, so change the div around index.html to navButtonOn?

actually thinking about it i should probably change the <a> to use the id so its easier to change and get rid of the <div> all together, but still how would i get it to change it? was thinking could check filename and then change the link with the filename that matches but troulbe is like with the services, you go to services page and then from there could go to domestic, commercial, but still want the services nav button to be on.
 
Last edited:
i'd store the pages in an array. loop through it then output the different class (not id because you have more than one) depending if the page matches the current page......

Code:
$pages = array(
'Home' => 'index.php',
'About' => 'about.php',
'Services' => 'services.php');

$current = $_SERVER['SCRIPT_NAME'];

foreach($pages as $title => $link) {
    $class = ($link == $current) ? 'buttonOn' : 'buttonOff';
    echo '<a class="' . $class. '" href="' . $link . '">'. $title . '</a>';
}

this does not take into account having subpages under services or whatever. :p
 
Back
Top Bottom