I am trying to learn PHP for a website that I am building. In CSS, I have a class, nav a.thispage
, setup to make a 'button' on the navigation be the same color as the highlight. It works beautifully. But, as I added pages, I find that I needed to constantly update all of the HTML files of the site, over, and over again. I found out that PHP could help me to automate this. I use the following PHP, in my HTML to do this:
<?php include 'content/header.php';?>
The header.php file has the following content:
<header>
<h1><img id="headerimage" src="Images/GrandLodge.png"/>Lodge</h1>
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="events.php">Events</a></li>
<li><a href="social.php">Social</a></li>
<li><a href="about.php">About</a></li>
<li><a href="contact.php">Contact</a></li>
<li><a href="gamestores.php">Area Game Stores</a></li>
<li><a href="http://someaddress" target="_blank">PFS</a></li>
</ul>
</nav>
</header>
Now, because I am using this method, I can't just set the class="thispage"
on the a tag. Is there a way to set the class, dynamically, with PHP? If so, how to I tell if the page loading the html is actually the page that needs it? Is using PHP even the correct way to handle this, or should I be using JavaScript?
I know this is a lot, and I didn't really provide a lot of what I have done, but I can't actually seem to see what I need to do for this. All I really need is a point in the right direction, rather than a full code sample.
Thank you for any help you can provide.