0

i think this question is very easy but I don't know if i am right. I am an oldschoool html, php coder. I want to use this kind of navigation: http://www.cssportal.com/horizontal-menus/13styles.htm

So far no problem. I got an dynamic php page and i want to use this Menu. There is no problem without this line in the HTML Part:

  <li><a href="" title="" class="current"><span>LINK</span></a></li>

The Problem is the class. What is the smartest way to detect which link is now current? I would do it in this way. I would write a php script like this pseudo code:

if acutaldocument == "link1.html" then echo "class='current' ";

But i think this is not the smartest way. Or am I right? Thanks

2 Answers 2

1

There's many options...

You can use session cookies, JavaScript, you can pass an id on the end of the url (eg. ?nav=2) or parse the URL and check against it...

All of them work... all of them have there pros and cons... just depends on how your page is set up...

Sign up to request clarification or add additional context in comments.

2 Comments

Parsing with php, like i said? There is no smarter way
Is it one page and you are changing the content on the page? or are these different pages? If it's the former, which it sounds like... you can use a cookie, some script... or if the url changes/variable passed you can check against/parse it. If it's the latter, then I'd just use a variable before any header information is fired and go from there... just depends on your set up.
1

Give each page's body tag an ID. Say, you give the About page's body tag the id "about". Give IDs for all your navigation <li>s too. Say, you give "about" id to the navigation <li>

In your CSS file, do this:

body#about li#about {
   // apply differentiating style here...
}

You can keep doing that for all other pages also. And only when both the body ID and the <li> ID match, the style is applied.

2 Comments

The problem is, i got only one php page with dynamic content. How can i give this page the right body id?
You can parse the URL. Chuck of the extension and use the file name as an ID?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.