hey guys, im trying to change a menu items color, if a user was on the members section, the member menu icon would be a different colour to the other menu items etc.

initially the menu item <li> has no css class assigned to it, but once they visit a page, the <li> tag is assigned a class ie .visited{colour:#fff;)

its implemented in php, firstly ive got a url check to see what page the current url is on, and then change the class

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 if($pageURL=="http://mysite.com/")
 {
     return 

 }
 else if($pageURL=="http://mysite.com/category.php?id_category=26")
 {
     help here..
 }
 else if($pageURL=="http://mysite.com/cms.php?id_cms=16")
 {
     and here..
 }
 else if($pageURL=="http://mysite.com/cms.php?id_cms=31")
 {
     and here..
 }
 else if($pageURL=="http://mysite.com/cms.php?id_cms=22")
 {
     and here..
 }



}

as you can see above, im finding it hard to finish the last piece to this puzzle.. how to change the class of the li tag to a different one. would really appreciate any input.

Cheers

D

Recommended Answers

All 2 Replies

I am not strong on PHP, but I would suggest that you look into doing this client side, using jQuery. You can easily add or remove classes. Take a look: http://api.jquery.com/addClass/

on the client-side, you can use the same approach to check the current URL, then add/remove the class as needed.

sorry forigve my lastreply, it works, but there because initally it had a hover styling ,where when the user hovers over a menu item, it reverts back to its original class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.