I am trying to manipulate a few things so that my "Work" nav stays highlighted for multiple pages not just work.php. Here is the code I have so far from this tutorial
Original:
PHP Code:
<?php
if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';
?>
HTML Code:
<ul id="navigation"><li><a <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?> href="index.php">Home Page</a></li><li><a <?php if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';?> href="about.php">About Me</a></li><li><a <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="current"';?> href="contact.php">Contact Me</a></li><li><a <?php if (strpos($_SERVER['PHP_SELF'], 'work.php')) echo 'class="current"';?> href="work.php">Work</a></li></ul>
This is the code found in the same tutorial that explains how to supposedly do what I am trying to do.
<?php
foreach ($aboutPages as $page) {
if (strpos($_SERVER['PHP_SELF'], $page)) echo 'class="current"';
}
?>
In the HTML code above, I am not sure what to insert in the php code in the <a> tag to identify the page. I tried $page but it didn't work. Any thoughts or help?
So you are saying put it all in the unordered list tag? When I tried that I get errors on "echo <li>;" "(strpos($_SERVER..." and the second "echo </li>;"
All I'm really trying to do is have my Work link in my main nav stay highlighted for multiple pages, not just work.php (such as work_print.php, work_web.php, etc). Hopefully that explains it better.
is the nav an include?
or is it hard coded on very page?
if it is hard coded then just add the class='current'
and build out the css to reflect that.
if it is included then you'll need to strip the url
PHP Code:
function ShowFileName($filepath)
{
preg_match('/[^?]*/', $filepath, $matches);
$string = $matches[0];
#split the string by the literal dot in the filename
$pattern = preg_split('/\./', $string, -1, PREG_SPLIT_OFFSET_CAPTURE);
#get the last dot position
$lastdot = $pattern[count($pattern)-1][1];
#now extract the filename using the basename function
$filename = basename(substr($string, 0, $lastdot-1));
#return the filename part
return $filename;
}
Yes that nav is in an include header.php file. Unfortunately I am not good at writing PHP and I am still not sure what you mean. Any example / tutorial you can point me to?
Looks like you are missing quotes on your echo. Do you see how the syntax highlighting looks strange? Also I'm assuming your *** are marking the lines with errors and are not actually included.
Bookmarks