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.

B

Recommended Answers

All 7 Replies

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

Thank you very much! Appreciated.

B

Member Avatar for diafol

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

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
/thisfolder/script.php

 <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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.