I am trying to set active classes in nav using php. Now I need to install it according to the directory, and not the full URL, since I have a main landing page for each directory with additional navigation for other pages in the directory. I was going to use the following, but this returns the full URL.
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;}
function activeLink($pageID) {
if ( $pageID == curPageURL() ) {
echo 'class="active"';
} }
Then I call activeLink () on a navigation element like this:
<li class="projectchild padding1"><a href="http://www.strangeleaves.com/nexus/index.php" <?php activelink('http://www.strangeleaves.com/nexus/index.php'); ?> >nexus</a></li>
Your suggestions on how to change this to return the catalog would be greatly appreciated.
source
share