Forum Moderators: coopster
I have a website hierarchy similar to this:
/
/folder1
/folder1/folder2
In each folder there is a file that has links to pages within it, so obviously it's easy enough to just name the page in my links and it just works. The same thing happens in folder2.
However, I would like to have pages in folder2 display links from folder1 and links in folder2, but the paths need to be relative to the current page (so it would be in folder2) without referring to folder1 by name (this would make it difficult to rename folder1 in the future, etc.).
I already have a variable called $DirR which refers to the root of the website (/). I COULD use this variable and 'folder1' to it but this would defeat the purpose.
I am new to PHP so any help would be appreciated.
I'm not sure I quite understand, but you can link one directory higher using ../
E.g. <a href="../">Next directory up</a>
/folder1/folder2/dir.php
<?php
$DirR = "../../"; // Points to server root
$Nav = "";
require_once("../dirMenu.php");
require_once("dirMenu.php");
?>
/folder1/dirMenu.php
<?php
$Nav .= "<div><h1>Folder1</h1><ul><li><a href=\"index\">Main</a></li><li><a href=\"anotherFolder1Page\">Another Folder 1 Page</a></li></ul></div>";
?>
/folder1/folder2/dirMenu.php
<?php
$Nav .= "<div><h1>Folder2</h1><ul><li><a href=\"index\">Main</a></li><li><a href=\"page2\">Page2</a></li></ul></div>";
?>
What I would like to do is have PHP correctly output the following for navigation when visiting a page in /folder1/folder2:
<div>
<h1>Folder1</h1>
<ul>
<li><a href="../index">Main</a></li>
<li><a href="../anotherFolder1Page">Another Folder 1 Page</a></li>
</ul>
<h1>Folder2</h1>
<ul>
<li><a href="index">Main</a></li>
<li><a href="page2">Page 2</a></li>
</ul>
But since the dirMenu.php file in folder1 does not already contain the ../ you see in the desired code, I need to somehow tell PHP how to generate that.
For your menu file - create another folder in root and call it something like "includes", place a single menu file there and then make all your other pages include from there.
Can it be done like that?