- Impact
- 11
Ever wondered how websites have different url navigation?
In this tutorial i will show you how to stop using the boring:
And teach you how to start using:
Now, 1st thing you need is a basic template with your header and navigation.
Create all your other files seperately not including the template structure.
Already done that?.. Now interigate this code into the part of your template you want the page to show up in.
Basicly, Heres the code broken down...
This starts the php code and "grabs" whatever the ?page= part of your URL is defined as, so that it can be used in the if/else statements.
The above sees if ?page= "index" and if it is, includes your index.php page, if it isnt it moves on to see if your page is something different.
After seeing if your page is set to index and finding out it isnt, this part of the code finds out if the ?page= is set to something else, in this case "contact"... and if it is set to contact, PHP includes your contact.php page.
You can add as many elseif statements as you like, depending on the number of pages you decide to use.
After finding out that $page is not equal to any of the pages you have set, the script then includes the default(index.php) page and ends the process.
I hope this tutorial has simplified the ?page=yourpage navigation and how it done, feel free to comment, constructive critacism is welcomed.
Thanks, Declan.
In this tutorial i will show you how to stop using the boring:
Code:
http://mysite.com/contact.php
http://mysite.com/faq.php
And teach you how to start using:
Code:
http://mysite.com/?page=contact
http://mysite.com/?page=faq
Now, 1st thing you need is a basic template with your header and navigation.
Create all your other files seperately not including the template structure.
Already done that?.. Now interigate this code into the part of your template you want the page to show up in.
PHP:
<?
$page = $_GET['page'];
if($page == "index"){
include"index.php";
}
elseif($page == "contact"){
include"contact.php";
}
elseif($page == "faq"){
include"faq.php";
}
else{ include"index.php";
}
?>
Basicly, Heres the code broken down...
PHP:
<?
$page = $_GET['page'];
PHP:
if($page == "index"){
include"index.php";
}
PHP:
elseif($page == "contact"){
include"contact.php";
}
You can add as many elseif statements as you like, depending on the number of pages you decide to use.
PHP:
else{ include"index.php";
}
?>
I hope this tutorial has simplified the ?page=yourpage navigation and how it done, feel free to comment, constructive critacism is welcomed.
Thanks, Declan.
Last edited:





