Forum Moderators: coopster
I'm new to all this, so please forgive me if this is a silly question. I've tried finding some answers before posting, but the available information is so overwhelming that I couldn't make much sense out of it.
I'm trying to create an included navigation that emphasizes the link to the currently loaded page. So far, everything's working fine, I've used the following code on each page to determine the page name
<?php $page = basename($_SERVER['SCRIPT_NAME']); ?>
and the following "if" statement in the <a href> tag in the included header.php to assign the corresponding css class:
<a href="/example.php" <?php if ($page == 'example.php') { ?>class="selected"<?php } ?>>Example</a>
This works fine until I reach a page that has a submenu that links to several pages in subordinate folders. As soon as I visit one of these pages, none of the links in the navigation is highlighted as I can hardly include every single page in these folders in the if statement. I would therefore like to create an addition to the if statement along the lines of
<a href="/example2.php" <?php if ($page == 'example2.php' or $path == 'XYZ') { ?>class="selected"<?php } ?>>Example2</a>
What exactly would I have to specify instead of the XYZ and - of course - in the head of the single pages?
I'd appreciate any help here, and again, I'm sorry if this is a dummy question...
Cheers,
Jakob
<a href="/example2.php" <?php if ($page == 'example2.php' or strpos($_SERVER['REQUEST_URI'],'/the/path/to/match/')!==FALSE) { ?>class="selected"<?php } ?>>Example2</a>