Hey, I’m new, so please understand if I put this in the wrong section.
I did a lot of programing before learning web design, so I’m constantly thinking about reducing redundancy, and making sure it’s easy to change the location of something.
I’ve run into a problem designing my site. The nav bar is the same on every page, and if I just copy-paste it, making changes to the nav bar (adding new pages, etc.) won’t be very easy. I tried php include, but that requires me to pass the path to each different directory as an argument in a function, which still requires me to change every page if I move something that was linked to in the navbar.
For example:
In navbar.php
<?php
function navBar($pathToHome, $pathToDir1, $pathToDir2) {
echo "<a href='".$pathToHome."'>Home</a>";
echo "<a href='".$pathToDir1."'>Dir1</a>";
echo "<a href='".$pathToDir2."'>Dir2</a>";
echo "<a href='".$pathToDir2."/myFile.html'>My File</a>";
}
?>
In /dir1/index.php
<?php
include('../navBar.php');
navBar("../", "/", "../dir2");
?>
I’d like to be able to link to files relative to the site root, so in my included php file, I don’t need to put anything in a function. Like so:
navbar.php
<?php
echo "<a href=''>Home</a>";
echo "<a href='dir1'>Dir1</a>";
echo "<a href='dir2'>Dir2</a>";
echo "<a href='dir2/myFile.html'>My File</a>";
?>
dir1/index.php
<?php
include('../navbar.php');
?>
Changing the location of a file would be as easy as changing it in the navbar.php file.
Is there any way at all that you can think of to accomplish this? I just can’t see sites like facebook changing millions (billions?) of pages just because they moved a file.
Sorry if I haven’t been clear, feel free to ask for clarification, and thanks in advance.