Welcome to WebmasterWorld Guest from 54.204.165.156

Forum Moderators: coopster & jatar k

Change font style based on current webpage?

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

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



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)

WebmasterWorld Senior Member 5+ Year Member



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)

10+ Year Member



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)

5+ Year Member



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)

10+ Year Member



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...
 

Featured Threads

Hot Threads This Week

Hot Threads This Month