I have really been struggling with this. I want to use one function to display all of my navigation, however links in certain directories should only be seen when a user is in the directory, and the page a user is on - it's link looks different than all the others. I am using css to depict the styles.
I think all I need is to do is get the result of the function in the class and check if the it is true or not, well that is what I have been trying, without success.
Here is my code, thanks in advance for the help!
<?PHP function do_nav() {
function on($page) {
if ($SERVER['PHP_SELF'] == $page) {
echo 'class="on" href="'.$page.'"';
} else {
echo 'href="'.$page.'"';
}
}
class sublinks {
function folder($folder) {
$location = dirname($SERVER['PHP_SELF']);
if ($location == $folder) {
true;
}
}
}
?>
<h3>
<?PHP $main = new sublinks();
if ($main == true) { echo '<span id="category">'; }
?>
<a <?PHP on('/index.php'); ?>>Ecuador Travel Guide</a><br>
<?PHP if ($main !== true) { echo '<!--'; } ?>
<a <?PHP on('/test.php'); ?>>General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br></span>
<?PHP if ($main !== true) { echo '-->'; } ?>
<?PHP $eco = new sublinks('/ecotourism');
if ($eco == true) { echo '<span id="category">'; }
?>
<a <?PHP on('/ecotourism/index.php'); ?>>Ecotourism</a><br>
<?PHP if ($eco !== true) { echo '<!--'; } ?>
<a <?PHP on('/ecotourism/test.php'); ?>>General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br>
<a href="test">General Travel LINK</a><br></span>
<?PHP if ($eco !== true) { echo '-->'; } ?>
</h3>
<?PHP
}
?>