469,085 Members | 1,017 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,085 developers. It's quick & easy.

How to check current url and specify #currentlink?

I use #currentlink in a nav list of links to indicate which page is
currently being viewed.

The code in the nav list looks like this:

<p><a href="index.php">Home Page</a></p>
<p><a href="contact.php">Contact</a></p>
<p><a href="tech.php#tech01">tech01</a></p>
<p><a href="tech.php#tech02">tech02</a></p>
<p><a href="tech.php#tech03">tech03</a></p>

The problem is that there are 3 named anchors on the tech.php page. If
there were no named anchors, and only one link to tech.php, I could do this:

<p><span id="currentlink"><a href="tech.php">tech</a></span></p>

That would change the color of the link as desired. But because there are
multiple links on the same page, I can't do this. So I need some php to
check the current url (I think) and echo the appropriate currentlink (again,
a guess) based on the url - so only the link referencing the current named
anchor will change color.

Here's some pseudo code:

<?php
/*
if ( current url = "tech.php#tech01" )
{
make "tech.php#tech01 the currentlink
}
elseif ( current url = "tech.php#02" )
{
make "tech.php#tech02 the currentlink
}
... and so on
*/
?>

Does this sound like the right way to go about this? How do I check the
current url, and how do I then get php to say the equivalent of :

<p><span id="currentlink"><a
href="tech.php#thisLink">thisLink</a></span></p>

Any help is appreciated!

By the way, the css code looks like this:

#currentlink a:link { color:#CC0000; }
#currentlink a:visited { color:#CC0000; }
#currentlink a:hover { color:#CC0000; }
#currentlink a:active { color:#CC0000; }
Jul 17 '05 #1
3 6801
> Does this sound like the right way to go about this? How do I check the
current url, and how do I then get php to say the equivalent of :


Here's half the puzzle. But how to set currentlink? - in standard html it
looks like this:
<p><span id="currentlink"><a href="tech.php#02">tech02</a></span></p>

<?php
$here = $_SERVER["PHP_SELF"];
//echo $here;
if ( $here == "/tech.php" )
{
//designate tech.php as currentlink
}
else if ( $here == "/tech.php#tech01" )
{
//designate tech.php#tech01 as currentlink
}
else if ( $here == "/tech.php#tech02" )
{
//designate tech.php#tech02 as currentlink
}
?>
Jul 17 '05 #2
Nonr of this returns the current named anchor - is it possible to get named
anchor with php? it appears in my browser's address window, but I can't
seem to find it in any variable.

$url = parse_url($_SERVER['PHP_SELF']);
$scheme = ($url[scheme]);
$host = ($url[host]);
$port = ($url[port]);
$user = ($url[user]);
$pass = ($url[pass]);
$path = ($url[path]);
$anchor = ($url[fragment]);
echo $scheme." = scheme<br>";
echo $host." = host<br>";
echo $port." = port<br>";
echo $user." = user<br>";
echo $pass." = pass<br>";
echo $path." = path<br>"; //==>> * * * this is the only thing i get
echo $anchor." = anchor<br>";

$url = parse_url($_SERVER['QUERY_STRING']);
$scheme = ($url[scheme]);
$host = ($url[host]);
$port = ($url[port]);
$user = ($url[user]);
$pass = ($url[pass]);
$path = ($url[path]);
$anchor = ($url[fragment]);
echo $scheme." = scheme<br>";
echo $host." = host<br>";
echo $port." = port<br>";
echo $user." = user<br>";
echo $pass." = pass<br>";
echo $path." = path<br>";
echo $anchor." = anchor<br>";
Jul 17 '05 #3
In article <gr*****************@newssvr27.news.prodigy.com> , deko wrote:
Nonr of this returns the current named anchor - is it possible to get named
anchor with php?


AFAIK it's not possible.

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Imayakumar | last post: by
2 posts views Thread by Ken Durden | last post: by
5 posts views Thread by LL | last post: by
7 posts views Thread by Sameh Ahmed | last post: by
12 posts views Thread by foolsmart2005 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.