homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Change font style based on current webpage?

 7:19 am on Oct 4, 2007 (gmt 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)

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)

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)

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)

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

#currentpage {
if ($thisPage=="Home")
echo " id=\"currentpage\"";?>>
<a href="#">Home</a>

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)

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved