Solved: I added the trim function around the str_replace function found in the functions.php file. Just turned to be a space problem
ey everyone, I have an array of links that I'm echoing out into an unordered list that I am using for a sites navigation.
I would like to change the color of a link to show that the user is currently on that page.
Here's the code I have so far:
functions.php
PHP Code:
function getScriptName() {
return str_replace('/', ' ',$_SERVER['SCRIPT_NAME']);
}
page.php
PHP Code:
$scriptname = getScriptName();
$links = array('index.php' => 'Home', 'portfolio.php' => 'Portfolio', 'page.php' => 'Blog', 'about.php' => 'About');
foreach ($links as $url => $description) {
if (strcmp($scriptname, $url) == 0) {
echo '<li><a href="' . $url . '" title=""><span style="background: #63AFD0;" >' .$description. '</span></a></li>';
}
else {
echo "<li><a href=\"$url\" title=\"\">$description</a></li>";
}
}
I tried echoing out the result of the string comparison, but it gave a -1 each time. Any ideas?
P.S. I have included the functions file in the page.php file.
Last edited by cchase88; 07-22-2010 at 02:32 AM..
|