This system pretends to have one file (index.php) and run the others (about.php, contact.php, ect.) inside of it
I read a lot of tutorials but later on, when my site had months running, i found about the PHP Switch Statement and this is the easiest way to have your PHP Navigation.
Copy and paste the code, you will find the explanaition in it.
< ?php
//First of all, let me tell you that you need to have a file with this code placed where you want the files to load and that if you include anyother file in the ones you are calling, you have to include them as if they were in the main folder.
//You can change $navigation to anything you want, like $page or $section but remember to change the 3 "navigation" words to your new one.
$navigation=$_GET['navigation'];
switch ($navigation) {
//You have to use it like this, when the file is in the same folder with the index. You can put any name in case and have the file in any folder at your site. http://www.yoursite.com/?navigation=section1
case "section1":
include('section1_file.php');
break;
//Another example, the file is in a subfolder but people wont know it, they will only see http://www.yoursite.com/?navigation=section2
case "section2":
include('section/section2_file.php');
break;
//As you can see in this last example, you can have your file in any place and put any name in your "case". http://www.yoursite.com/?navigation=lastsection
case "lastsection":
include('folder1/folder2/section3.php');
break;
//This will be your index or default page you want to show when people has just landed on your site and this will be the page it will show when people try to access any page that you havent declared here.
default:
include('home.php');
}
?>
Page include system for newbies
This system pretends to have one file (index.php) and run the others (about.php, contact.php, ect.) inside of it
I read a lot of tutorials but later on, when my site had months running, i found about the PHP Switch Statement and this is the easiest way to have your PHP Navigation.
Copy and paste the code, you will find the explanaition in it.
< ?php //First of all, let me tell you that you need to have a file with this code placed where you want the files to load and that if you include anyother file in the ones you are calling, you have to include them as if they were in the main folder. //You can change $navigation to anything you want, like $page or $section but remember to change the 3 "navigation" words to your new one. $navigation=$_GET['navigation']; switch ($navigation) { //You have to use it like this, when the file is in the same folder with the index. You can put any name in case and have the file in any folder at your site. http://www.yoursite.com/?navigation=section1 case "section1": include('section1_file.php'); break; //Another example, the file is in a subfolder but people wont know it, they will only see http://www.yoursite.com/?navigation=section2 case "section2": include('section/section2_file.php'); break; //As you can see in this last example, you can have your file in any place and put any name in your "case". http://www.yoursite.com/?navigation=lastsection case "lastsection": include('folder1/folder2/section3.php'); break; //This will be your index or default page you want to show when people has just landed on your site and this will be the page it will show when people try to access any page that you havent declared here. default: include('home.php'); } ?>No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.