Now, i know a lot of php navigations use switch. This means that the switch calls upon a case from a list of cases to switch between. This can save you a lot of files, as pages are kept lower. However, if you have a website that requires lots of pages, and you dont want to have to constantly update your navigation.php file or whatever, then take a look at this:
So, with all php, we need to start with our opening and closing tags:
<?php ?>
Right, now we need some variables in the code:
<?php $folder = $_GET['folder']; $page = $_GET['page']; ?>
This will use the $_GET method of receiving our folders and pages from the url.
Now we get to the if statements:
<?php
$folder = $_GET['folder'];
$page = $_GET['page'];
if (empty($page)) //if the page is empty
{
include('home.php'); //include your default page
}
else //otherwise,
{
include('error_page.php'); //include an error page, if the page cannot be found.
};
};
?>Now this is great, but it either displays home.php or error_page.php, it wont actually show any of our pages, so
This will now use the variables to get the folder and page:
<?php
$folder = $_GET['folder'];
$page = $_GET['page'];
if (empty($page)) //if the page is empty
{
include('home.php'); //include your default page
}
else //otherwise
{
if (file_exists($folder . '/' . $page . '.php')) //if the folder and page exists
{
include($folder . '/' . $page . '.php'); //include that folder and page
}
else //otherwise
{
include('error_page.php'); //include an error page, if the page cannot be found.
};
};
?>Now all you need to do, is make your links look like this:
<a href="http://www.yoursite.com/index.php?folder=news&page=latest.php" alt="">Latest News</a> //i use & because its more valid than &or something like that.
Help


















