Sorry if this is a nooby question, but I have the following problem: I have some sort of a Documentation as a multiple webpages. I created a basic navigation bar on the left of the screen using a tutorial... To be able to mark the active link every page has its own unique navigation adding it's own link to a specific div class. The problem is that if I wanted to add another page to my collection I would have to add the link in every html document. I know that there is a possibility to include other pages Php code to have one navigation document, but I have no idea on how to achieve that the current page is getting highlighted. I would appreciate any help.
-
Are you asking about making external class/function or how to pass them information about which page is active? – Grzegorz J Feb 18 '16 at 21:53
-
A little bit of both, but mostly on how to pass the information. I'd prefer Php instead of JScript – RoiEX Feb 18 '16 at 21:55
3 Answers
If you want to have your navigation on a separate file it is completely possible and is actually preferred.
Use any of the following:
So let's say your navigation HTML is located at nav.php
you would do something like:
<html>
<head><title>My Awesome Website</title></head>
<body>
<div id="nav-wrapper">
<?php
include_once("nav.php");
?>
</div>
<div id="contents">
<h1>Hello World!</h1>
</div>
</body>
</html>
If you update your navigation in the future you will only need to update one file (nav.php
).

- 4,957
- 3
- 39
- 77
So if you want to make a new function please read this: http://php.net/manual/en/functions.user-defined.php There is full info how to create function. Pass to function what page is active you can just simply in this way:
function menu($active)
{
echo $active;
}
menu($active);
It's hard to say more, because you didn't show us anything, a construction of HTML or PHP. Please read linked above tutorial. I think it will be enough in this stage of PHP learn.

- 82
- 5
Because of Grzegor J I found this Stackoverflow question which pretty much solves my problem. Thanks to everyone for trying.