I am dealing with the following kind of choppy code while trying to figure this out.
<?php $curURL = ROOT.$_SERVER['REQUEST_URI']; ?>
<li><a href="<?php $href = APP_ROOT; echo $href; ?>" class="<?php if($href == $curURL) { ?>main_active<?php } ?>">HOME</a></li>
<li><a href="<?php $href = APP_ROOT.'about'; echo $href; ?>" class="<?php if($href == $curURL) { ?>main_active<?php } ?>">ABOUT</a></li>
<li><a href="<?php $href = APP_ROOT.'portfolio'; echo $href; ?>" class="<?php if($href == $curURL) { ?>main_active<?php } ?>">PORTFOLIO</a></li>
<li><a href="<?php $href = APP_ROOT.'services'; echo $href; ?>" class="<?php if($href == $curURL) { ?>main_active<?php } ?>">SERVICES</a></li>
<li><a href="<?php $href = APP_ROOT.'blog'; echo $href; ?>" class="<?php if($href == $curURL) { ?>main_active<?php } ?>">BLOG</a></li>
<li><a href="<?php $href = APP_ROOT.'contact'; echo $href; ?>" class="<?php if($href == $curURL) { ?>main_active<?php } ?>">CONTACT</a></li>
The result I am currently getting is that if I am on the selected pages url (ex. http://localhost/myapp/index/) then it will change the css style accordingly. What I am looking to have happen is that the css style will remain changed even if I am on a sub url of that page (ex. http://localhost/myapp/index/dosomething/). Ive been banging my head against the wall on this one for a while.
This is how I do it on one of my sites. This is a sample that applies a class to an active link, but the idea is the same…
PHP
HTML