Hi all,

I am wondering if I need to make multiple copies of the same include xxx.php (navigation) file in order to highlight which page the user is on. Using an include seems almost unnecessary if I do. Can you please let me know.

Thank you.


Edited by happygeek: moved

1 Year
Discussion Span
Last Post by almostbob

there is a jaquery plugin active.js which adds a class to your current selected page. sorry cant find the url for it


THis would usually be done on the server rather than javascript, as most sites these days employ a front page (index.php) and use Apache mod-rewrite to 'prettify' their urls. This means that the server picks up something like: $_GET['page'].

It may depend if your nav menu is created dynamically or if it's static html. If it's static HTML, it may be more hassle than it's worth, so a js/jQ solution may be easier. A dynamically created menu shoould be relatively easy to retrofit.


you only need one nav include::
the included nav menu file becomes part of the outer file,$_SERVER['PHP_SELF'] in the include refers to the outer file href
code to disable the link to the current page can be written based on comparison to $_SERVER['PHP_SELF']

css :: .notlinked {pointer-events: none; cursor: default;}

<a <?php if($_SERVER['PHP_SELF']='href'){echo 'class="notlinked" ';} else {echo 'class="menu" ';} ?> href='href' > link text </a> 

you must write the href in your menu links, the same as $_SERVER['PHP_SELF'] expresses the href for the comparison to work

Edited by almostbob


waited too long to edit
you must write href in the php comparison the same as $_SERVER['PHP_SELF'] expresses the href for the comparison to work

$_SERVER['PHP_SELF'] expresses the href as document_root/folder/file

 <a <?php if($_SERVER['PHP_SELF']='/thisfolder/script.php'){echo 'class="notlinked" ';} else {echo 'class="menu" ';} ?> href='http://mysite.com/thisfolder/script.php' > link text </a>

outputs <a class="notlinked" href='http://mysite.com/thisfolder/script.php' > link text </a> an is effected by css disabling pointer actions

Edited by almostbob


dammit, I have to start reading what I type
<?php if($_SERVER['PHP_SELF']=='/thisfolder/script.php')

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.