javascript text class change for heading

jakeselectronics

New Member
Messages
38
Reaction score
0
Points
0
I am changing my site over to use php includes to make it easier to update as the site grows.

I have come across an issue.

I have a menu and say for instance i am on the home page. 'Home' will be in lighter text because of a different class used for the home page.

When you move onto another page, say for instance the contact page. the text 'Contact' will now be lighter...

But using a php include file for the menu prevents me from changing the colour/shade of the text depending on which page your on becasue the menu will be universal.

Or can I still use 1 php include file for the menu, and change the text class (to change text shade) depending on which page i am on.
Like an If statement in the include...
Code:
<td>
<a href="index.html" class="************">Home</a>
</td>

example: If on home page, show light text. else show dark text

Check out my site to see how it performs now... How do i acheive the same result using an include file for the menu.
Can this be done with javascript?




Edit:
Never mind....
I worked it out.
Found a code here perfect for what i needed...
http://www.maketemplate.com/menu/
 
Last edited:

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
I would do it inside php. For instance, in each page, I'll set a variable named 'rootMenuActive':
PHP:
<?php
//a page in your website
$rootMenuActive = 'home';
// ...
// the rest of the page code
?>
Then in the header.php file, I'd use if statements to find which root menu should be activated:
PHP:
<?php
// header.php

echo "menu code...";
if ($rootMenuActivate = 'home') {
   echo '<a href="index.html" class="************">Home</a>';
} else {
   echo '<a href="index.html">Home</a>';
}
// .. 
?>

This code is very rudimentary, and you can improve it easily.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
$_SERVER[ 'PHP_SELF' ] gives you the path to the current script.

That lets you figure out which link to give the special class to. (personally, I do not like the link to be active at all).

PHP:
# array of arrays with  LINK_TEXT and LINK_PATH
# add to array as site grows, etc


$pages = array( 
             array( 'Home' , '/index.php' ) , 
             array( 'Links' , '/lynx.php' ), 
             array( 'Test' , '/phptest.php' )
         ) ;

$links = array() ;

foreach( $pages as $page ){

      if( $page[1] == $_SERVER['PHP_SELF'] ){
            $links[] = '<a href="' . $page[1] . '" class="current" >' . $page[0] . '</a>' ;
      } else {
            $links[] = '<a href="' . $page[1] . '" class="other" >' . $page[0] . '</a>' ;
      }
}
  
# Now you can use $links to build your menu.
 
Top