Hi,
If you are building small websites without any frameworks... here is a small code that will add to the anchor in the menu, the class "selected" - and then you do whatever you want with it in CSS.
PHP Code:
// first need to include the JQuery URL Parser plugin - https://github.com/allmarkedup/jQuery-URL-Parser
$(document).ready(function() {
selectCurrentMenuLink();
});
function selectCurrentMenuLink () {
//$.url(); is a jquery plugin
var url = $.url();
$('#Menu a').each(function() {
//if the href of a particular a == the url of the page - make page selected
if ($(this).attr('href') == url.attr('file')) {
$(this).addClass("selected");
} else {//remove the selected class
$(this).removeClass("selected");
}
});
}
the html code can look something like:
PHP Code:
<div id="Menu" class="box1" >
<ul>
<li><a href="index.php"><span>Home</span></a></li>
<li><a href="websites.php"><span>Websites</span></a></li>
<li><a href="portfolio.php"><span>Portfolio</span></a></li>
<li><a href="about.php"><span>About me - CV</span></a></li>
<li><a href="contact.php"><span>Contact</span></a></li>
</ul>
</div>
What happens is that you loop trough all the anchors in one div (menu) and if one of them == the link of the current page, the class selected is added to the anchor...
Cheers!
PS
I have an issue with it on my website and currently not working - but is only happening on this server - on my server is working fine... please let me know if is working for you.