Forum Moderators: coopster
I've got a php-generated nav bar. When you click one of the links in this bar, it sends a href query string (i.e. <a href="index.php?pageId=indu1">somelink</a> to index.php which then loads the correct content. Works perfect.
The way I've written this though, is that as the nav bar is refreshed, it checks the "pageId" var. If any particular nav item equals the contents of that var, the link is nulled ("#"), and a css class name is written within the href - changing the link color and indicating that you are on THAT page. It's like this:
$pageID = $_GET['pageId'];
<ul>
<?php
$pageID == 'home'
? print '<li><a href="#" class="active">Home</a></li>'
: print '<li><a href="index.php?pageId=home1">Home</a></li>';
...
</ul>
The hilighting of the landing page link works fine as well ... UNTIL you click on the HIGHLIGHTED link! then it becomes un-hilighted (even though it's null). -- "oh, because it's passing the null so Get doesn't know what it's got!"
So, instead of this:
print '<li><a href="#" class="active">Home</a></li>'
I did this:
print '<li><a href="index.php?pageId=home1" class="active">Home</a></li>'
But I've got the same problem and I can't for the life of me figure out what's going on - or not as with my "solution" I'm getting the correct $pageId var.
Last thing I did was to clear my cache because I thought something got "stuck", reloaded my page, and the correct landing page highlight showed again.
Has this happend to anyone else? Is it a cache problem? If so, can someone please share their solution?
Great appreciation in advance!
Neophyte
print '<li><a href="index.php?pageId=home1" class="active">Home</a></li>'
You have the pageID as "home1" but you are checking it in the code above for "home". Otherwise, I don't immediately see anything wrong.
Thanks for the input (as always!).
The "home" was a typo on my behalf. It really DOES check home1.
From a "best practices" point of view, is it better to put the entire query string within an "active" href, or is it okay to null the href? What do the Pros do when there is such a requirement?
So, darn! I'm not sure where to go from here. Yes, the logic and flow DOES seem to be correct to me as well.
Why would it be that when you click a link that's already active, that it would de-activate the hilight... then when you clear the cache and re-load the page the highlight returns? Or even when you send the same query with the same vars on an active link, you get the same (unacceptable) result?
I'd like to blame the browser (of course), but then again, the client won't accept such excuses for such a minor - yet required - piece of functionality.
Any other guesses/guidance on what I can try?
Neophyte
echo (isset($_GET['page']) && $_GET['page'] == 'one')? '<a href="#" class="active">one</a>':'<a href="index.php?page=one" class="not_active">one</a>';
echo (isset($_GET['page']) && $_GET['page'] == 'two')? '<a href="#" class="active">two</a>':'<a href="index.php?page=two" class="not_active">two</a>';
To be honest, I'm not sure what is happening to you.