Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] PHP to add conditional css classes?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26894
    jmizi
    Member

    Hi,
    I am using the jquery lavalamp plugin for a piece of navigation, and the plugin requires that <li> for the active page must have a class of "current"… and that is what makes it highlight the appropriate page. Thats all fine and dandy…

    My problem is that for my navigation, I have one php file with all my navigation that the rest of my pages link to using php insert. So just setting one <li> as current would highlight only one navigation option throughout all the pages.

    What im wondering is if theres a way to have a php statement that says that "if the body id="blabla", then put "current" in li class. If not then dont do anything."

    Code:

    This way, for example, on the home page it will see that my body id = "home" and then insert the "current" class into the <li> tag for the home link, and that one will be highlighted on the home page. And when the body id ="about", it will highlight the about link…. etc.

    Thanks so much… any help will be greatly appreciated. At least if someone can tell me if this is even possible or not.

    #66947
    AshtonSanders
    Participant

    This sounds like you are working on a custom-programmed site.

    Yes it’s possible, but you need to somehow tell your navigation file what page you are on.

    Here’s one example I’ve done:

    Code:

Each If statement checks to see if $pg == the page name, and then echo’s current into the class if so.

Hope that helps.

#66949
jmizi
Member

thanks! … now should i put

Code:

in my navigation php file, or in each of my actual page files?

heres what my navigation file looks like:

Code:

I must be doing something wrong, because its not catching it. Here is the link to the test site:
http://mizirawi.com/justinmizirawi/index.php

The only working links are home and about… it defaults to home. But when i go to the about page… it should highlight that link

#66952
jmizi
Member

All fixed…. i just needed to put the folder name before the actual file so PHP_SELF could recognize it. Thanks for all your help AshtonSanders! :D

#66962
AshtonSanders
Participant

Awesome. Glad it worked.[img]http://www.websitesinaflash.com/images/thumbsup.gif[/img]

Viewing 5 posts - 1 through 5 (of 5 total)