I’m trying to get the class of a ul based menu to change according to what page is being viewed. Here is what I have so far:
In a separate file (nav.php)
<div id="menu">
<ul id="menu_ul"
<li<?php if ($thisPage=="home")
echo " class=\"current_page_item\""; ?>><a title="Home" href="index.php">Home</a> </li>
<li<?php if ($thisPage=="about")
echo " class=\"current_page_item\""; ?>><a title="About Us" href="about.html">About</a> </li>
<li<?php if ($thisPage=="contact")
echo " class=\"current_page_item\""; ?>><a title="Contact" href="index.php?id=6">Contact</a> </li>
<li><a title="View upcoming events" href="/forum/index.php?action=calendar">Calender</a></li>
<li><a title="Hang out in the forums" href="/forum">Forums</a>
</li>
</ul>
</div>
Then I use a snippet to include nav.php in the template
Now the problem I am having is in order to make the $thisPage call work each page has to have the following code at the top so it is parsed before the page loads
<?php $thisPage="home"; ?>
(or replace home with whatever the page name is)
I tried using that as a snippet and just put it on each page right before the content...but it doesn’t parse it before the page loads. Any help would be greatly appreciated.
I also wanted to add that the nav.php loads correctly, but it doesn’t change the class of the li to reflect the current page.