Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php Navigation, How to make your navigation based on php
maddog39
post Mar 12 2005, 08:46 PM
Post #1


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



I have re-constructed my last PHP Navigation system and it works great. So I have it here for you guys. Here are the instructions.

INSTRUCTIONS:
Open your main page for your site in your text editor and paste in the following code where the main content goes.
CODE

<?php
error_reporting (E_ALL ^ E_NOTICE);
if(!$page){ $page = $HTTP_GET_VARS['page']; } //You can change 'page' to whatever you want.

//Default Page
if($page == "" or $page == "index"){
include("main.php"); //You can change 'main.php' to whatever you want.
}
//Secondary Pages
if($page == "something") {  //Change 'something to what you want.
       include("something.php");  //Change 'something.php' to the page your including.
}
if($page == "something") {
       include("something.php"); //^Follow Above^//
}
if($page == "something") {
       include("something.php"); //^Follow Above^//
?>

Also when your doing this, take any other content in the main content box and put it into another file, probably main.php since that is set default but you may change that. You can also add pages by adding another...
CODE

if($page == "something") {
       include("something.php");
}

under the existing pages in that php block.

Then save the page to your server and make sure that all other pages of your site are plain text or just dont have the site template in them. Also make sure that your index page has an ending of '.php' or this will not work.

When changing the URLs your pages will now be accessed by 'index.php?page=something' but obiously change 'something' and the 'page' to page names you put in the php code. Got it?

Well thats about it and if you need any help just ask me. biggrin.gif
Go to the top of the page
 
+Quote Post
karlo
post Mar 13 2005, 02:49 AM
Post #2


Privileged Member
*********

Group: Members
Posts: 618
Joined: 30-October 04
From: Philippines
Member No.: 2,049



QUOTE(maddog39 @ Mar 13 2005, 04:46 AM)
I have re-constructed my last PHP Navigation system and it works great. So I have it here for you guys. Here are the instructions.

INSTRUCTIONS:
Open your main page for your site in your text editor and paste in the following code where the main content goes.
CODE

<?php
error_reporting (E_ALL ^ E_NOTICE);
if(!$page){ $page = $HTTP_GET_VARS['page']; } //You can change 'page' to whatever you want.

//Default Page
if($page == "" or $page == "index"){
include("main.php"); //You can change 'main.php' to whatever you want.
}
//Secondary Pages
if($page == "something") {  //Change 'something to what you want.
       include("something.php");  //Change 'something.php' to the page your including.
}
if($page == "something") {
       include("something.php"); //^Follow Above^//
}
if($page == "something") {
       include("something.php"); //^Follow Above^//
?>

Also when your doing this, take any other content in the main content box and put it into another file, probably main.php since that is set default but you may change that. You can also add pages by adding another...
CODE

if($page == "something") {
       include("something.php");
}

under the existing pages in that php block.

Then save the page to your server and make sure that all other pages of your site are plain text or just dont have the site template in them. Also make sure that your index page has an ending of '.php' or this will not work.

When changing the URLs your pages will now be accessed by 'index.php?page=something' but obiously change 'something' and the 'page' to page names you put  in the php code. Got it?

Well thats about it and if you need any help just ask me. biggrin.gif
*

Or, you can just try the following:
CODE
<?php
if(isset($_GET[page])){

include($_GET[page].".php");

}
<!-- then put your html code here -->
?>

So, if the file requested on the "page" dosen't exists, it will just ignore it and outputs the default page or the main page (the one on the bottom of the script).
Go to the top of the page
 
+Quote Post
karlo
post Mar 13 2005, 02:51 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 618
Joined: 30-October 04
From: Philippines
Member No.: 2,049



QUOTE(karlo @ Mar 13 2005, 10:49 AM)
Or, you can just try the following:
CODE
<?php
if(isset($_GET[page])){

include($_GET[page].".php");

}
<!-- then put your html code here -->
?>

So, if the file requested on the "page" dosen't exists, it will just ignore it and outputs the default page or the main page (the one on the bottom of the script).
*

OOPS! I CREATED A WRONG CODE! HERE IT IS AGAIN!

CODE
<?php
if(isset($_GET[page])){

include($_GET[page].".php");

}
?>
<!-- then put your html code here -->
Go to the top of the page
 
+Quote Post
maddog39
post Mar 13 2005, 03:21 AM
Post #4


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



Ahhh I dont like that way. I used something similar before....
CODE

<?php
$Page = $_GET['page'];
@include ($Page . ".php");
?>

and I didnt like it at all.
Go to the top of the page
 
+Quote Post
Plenoptic
post Dec 29 2005, 09:55 PM
Post #5


Trap Double Mocha Member
***************

Group: [HOSTED]
Posts: 2,224
Joined: 5-November 05
From: That one place over there...
Member No.: 13,830



This tutorial was written by me and is used on my site. http://plenopticdesign.com/index.php?id=1

This tutorial will teach you how to make a navigation system using php. So instead of having your url to your affiliates page like this http://yourdomain.com/affiliates.htm it will be like this http://yourdomain.com/index.php?id=affiliates This is a better way than to use iframes, it is more efficient. So let's get started.
We will start with this code here.
CODE
<?php switch ($HTTP_GET_VARS[id])
   {
   //Default - case
   case 'content':
   default:
   include 'content.htm';
   break;

The switch tells you that all of the content won't be in there at once. HTTP_GET_VARS tells it to get these when called. This first one is the default one seen when you first enter the page. [id] is the case, meaning that it will be index.php?id=whatever You can change that to whatever you would like. So if you were to change it to [content] then it would be index.php?content=whatever. Put whatever file name you would like after the include, that is the file that will show up in the content area.
The next part of the code will be this.
CODE
   //Resources - case
   case 'resources':
   include 'resources.htm';
   break;
   //About Us - case
   case 'aboutus':
   include 'about.htm';
   break;

This is the other pages you would like to be in your content area. These you have to call up which will be explained later. You won't be able to see these until you go to the link. Now to close the code put this in.
CODE
}
?>

There you have it. You now can access your pages using php. All you have to do is when you put the link type
CODE
<a href="index.php?id=whatever" ?>
This whatever will be replaced on whatever you put in where it says case 'aboutus': Make sure to save your page as .php if it is not already. I hope this tutorial has helped.

Notice from KuBi:
Edit as per requested.


This post has been edited by KuBi: Dec 29 2005, 11:16 PM
Go to the top of the page
 
+Quote Post
BuffaloHELP
post Dec 29 2005, 11:34 PM
Post #6


Desperately seeking "any key" to continue...
Group Icon

Group: Admin
Posts: 3,497
Joined: 23-April 05
From: Trap17 storage box
Member No.: 6,042



Merged two similar topics into one.

Please search the forum before making a new topic. You must QUOTE even if you wrote it when it's published elsewhere BEFORE posting in Trap17's forum.
Go to the top of the page
 
+Quote Post
Tyssen
post Dec 30 2005, 12:29 AM
Post #7



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



Instead of http://yourdomain.com/index.php?id=affiliates, you can do this instead: http://yourdomain.com/?id=affiliates. It looks neater.
I actually prefer Karlo's method. With the switch method, you have to write out a line for every possibility, whereas if the include has the same name as the querystring value, you just need one line of code.
Go to the top of the page
 
+Quote Post
bucksta
post Jan 4 2006, 12:02 AM
Post #8


Advanced Member
*******

Group: Members
Posts: 127
Joined: 6-December 05
Member No.: 15,438



hmm. looks decent...
Go to the top of the page
 
+Quote Post