Welcome to WebmasterWorld Guest from 54.162.94.181

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Change font style based on current webpage?

     
7:19 am on Oct 4, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts:229
votes: 0


I have links in a navigation bar. I'd like to make the link, where the visitor currently is, bold. This way they know where they are in my website. Is there anyway of doing this with php?
7:52 am on Oct 4, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


Can be done in two steps:

> grab the current URL
> Write conditions on the links as to when should a link appear bold

If you provide more details, you will get more specific answers.

9:55 am on Oct 4, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts:229
votes: 0


If someone is on index.php I'd like to output:

<span class="currentpage"><a href="index.php">Home</a></span>

otherwise just output:

<a href="index.php">Home</a>

11:37 am on Oct 4, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:July 12, 2007
posts:766
votes: 0


Have a look at [webmasterworld.com...]

As getting the current page is easy if you use javascript

[edited by: PHP_Chimp at 11:38 am (utc) on Oct. 4, 2007]

4:24 pm on Oct 4, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts:229
votes: 0


I couldn't get the javascript to work, but I did find a way with php:

$thispage="Home";
<html>
<style>
#currentpage {
text-decoration:underline;
}
</style>
<body>
<ul><li
<?php
if ($thisPage=="Home")
echo " id=\"currentpage\"";?>>
<a href="#">Home</a>
</li></ul>
?>
</body>
</html>
------------------------

The downside is each page has to be assigned a value for $thispage. Could this be done automatically somehow with just php?

4:37 pm on Oct 4, 2007 (gmt 0)

Preferred Member

5+ Year Member

joined:Jan 16, 2007
posts:477
votes: 0


Yea, if ur using different scripts for navigation. i think this would at least point you in the right direction

if(strpos($_SERVER['PHP_SELF'], "index.php")){
//then index.php is current
}

elseif(strpos($_SERVER['PHP_SELF'], "pagex.php")){
//then pagex is current
}

other wise if ur navigation is more dynamic, such as using "index.php?page=pagex" to navigate, u can use the $_GET['page'] to get the current page

8:18 pm on Oct 8, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 16, 2005
posts: 88
votes: 0


this could really be done with css easier than with php...just name the class of your nav the same as your page and then use a flag, like body id="" and name it the same as the class you want highlighted, then check in css and highlight...