Hey guys, continuing with my page here, has there been a post or a tutorial somewhere on how to setup your pgae navigation like this:
www.test.com/index.html?p=news
I'm sure its not that advanced, but I would like to learn how to do it.
| SitePoint Sponsor |

Hey guys, continuing with my page here, has there been a post or a tutorial somewhere on how to setup your pgae navigation like this:
www.test.com/index.html?p=news
I'm sure its not that advanced, but I would like to learn how to do it.

Just to add....will this make it so I only have to do the navigation bar etc on index.html, so when I have to change a link, I dont have to do it 20 times?
Wouldn't it be index.php...? I'm not sure.
But anyways, I was wondering how to do the same. :\




I think what you are looking for are includes, not calling all content from a single page. That allows you to include a nav bar on every page with only one file to edit. This is something I started working on about this. Check it out and see if this helps.
http://www.ricksweb.info/php/tutorials.php?ID=1
mitechie.com
"Techies just think a little differently
...at least that is what they keep telling me."

hrm...that just explains includes, don't think its what I am looking for. See how on your page it says ID=1, i need to do that ie. ID=news.





it's done by using a database![]()
i love php





Not necessarily. Check out this code:Originally Posted by i_like_php
You can save this code as index.php and then call any page you want by using index.php?p=news (assuming that a news.php file exists). [img]images/smilies/smile.gif[/img]PHP Code:<?php
$this_page = explode('/', $_SERVER['PHP_SELF']);
$this_page = $this_page[count($this_page)-1];
$request = $_GET['p'].'.php';
if (file_exists($request) && $this_page != $request)
{
include $request;
}
else
{
echo 'There was a problem with your previous action...';
}
?>

Well say they goto index.php?p=media
I need it to goto the media page, then they goto index.php?p=pictures and it goes to the picture page, get my drift?





Umm, spot-on. [img]images/smilies/smile.gif[/img] That's what my code sample does for you. You could (and you'll probably want to) extend the snippet by including a header and footer, and voila--you've got a barebones templating system.Originally Posted by MarshallX
Just making sure....Originally Posted by mattjacob
So, any page could be called upon just by the URL: site.com/index.php?p=page.php?





Nope. The query string would look like http://www.yoursite.com/index.php?p=photos, where the file photos.php already exists in your root directory. To call files in other directories, use something like http://www.yoursite.com/index.php?p=foo/bar/pepsi, where pepsi.php exists in /foo/bar on your server. Sorry for the Pepsi example, but I've got a can of it sitting here in front of me.Originally Posted by koomann
![]()
Thanks matt.
But what exactly would something like this be used for?





It's really just to make things simpler on you. You would probably include a header file that has your navigation in it and also a footer with copyright information or whatever. Then you could update those two files and changes would be reflected across your entire site.





so are you saying i can use this code instead of using a database to get the same results?Originally Posted by mattjacob
also does this page name need to be named index.php or can you name it whatever you want?![]()
i love php

Well, to suit my needs, all I did was where the table that I needed my content was I put:
<?php if($page=="news") include("gennews.php")?>
etc, for each page. Works fine!
Hm, nifty little idea there Marshall...I'll be using this sooner or later![]()





Oy vey.Originally Posted by MarshallX





Not really. Call it a poor man's database.Originally Posted by i_like_php
You can call it whatever you want. Some suggestions: template.php, yoursitename.php, loader.php, whatever.Originally Posted by i_like_php
Bookmarks