Page 1 of 1

[SOLVED] "Current" link, need script help please:

Posted: Fri Oct 01, 2004 9:31 pm
by mhulse
("Current" link, need script help please:)

Hello,

Here is my script:

Code: Select all

<?php
function foLinks($link)
{
	//$pages pops an array with links set by webmaster
	$pages = array (
					"Interactive" => "folio.php?display=interactive",
					"3D" => "folio.php?display=3d"
					);//Add the links here
	
	//$pages pops an array with link-related titles set by webmaster
	$titles = array (
					"Interactive" => "&rarr;&nbsp;ambiguism&nbsp;&larr;&nbsp;{Interactive]",
					"3D" => "&rarr;&nbsp;ambiguism&nbsp;&larr;&nbsp;{3D]"
					); //Add the titles here
	$my_title = $titles[$link];

	//Use $test to add $pages[$link] to $page for comparison:
	$test = str_replace("folio.php", "", $pages[$link]);
	//remove /'s and replace with ""
	$page = str_replace("/", "", $_SERVER['SCRIPT_NAME']).$test;
	//Compare URL to links for display of current and non-current nav links:
	//If page is current, set the link to "#" and set CSS class to "current"
	if($page == $pages[$link]) {
		echo "&nbsp;&nbsp;<span class="arrow">&laquo;</span><a href="#" class="current" title="$my_title">$link</a>";
	} else {//set to non-current style
		echo "&nbsp;&nbsp;<span class="arrow">&raquo;</span><a href="$pages[$link]" title="$my_title">$link</a>";
	}
}
//This next linke displays the links on the page:
foLinks("Interactive");
echo "<br />";
foLinks("3D");
?>
The above script is supposed to set a CSS "current" link-style to the currently selected links/page... I can't seem to get it to work though, both links think they are current...

Could someone help me with this one? I am having troubles seeing my logic error(s).

Thanks in advance, I really appreciate any help anyone can give me. :)

Cheers!
Micky

Posted: Fri Oct 01, 2004 10:30 pm
by mhulse
Duh, it was pretty obvious answer...

I just had to delete this:

Code: Select all

//Use $test to add $pages[$link] to $page for comparison:
$test = str_replace("folio.php", "", $pages[$link]);
And replace this:

Code: Select all

$page = str_replace("/", "", $_SERVER['SCRIPT_NAME']).$test;
With this:

Code: Select all

$page = str_replace("/", "", $_SERVER['REQUEST_URI']);
Thanks anyways, sorry to take up space on the forums.

Cheers
M