index.php?pagename

  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

I am starting to create a template using PHP that allows users to have one main page(that being index.php) and the information for the pages, i.e. main, about, prices e.t.c) being stored ina seperate pages that can be included. Here is a brief code idea for it, none of this is right, it's jsut how I would like it work. Can anyone help with the php for this?
Code: [ Select ]
if ($page == "") include ("main.php");
else if ($page != "" && $page == "about.php") include (about.php);
  1. if ($page == "") include ("main.php");
  2. else if ($page != "" && $page == "about.php") include (about.php);


Something like that.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1853

Post 3+ Months Ago

For starters, you have include (about.php) when I'm sure you mean include ("about.php").

You haven't shown how you arrived at $page.

You are going about this the wrong way, though. It is much more user-friendly to have URLs that are readable, such as example.com/about or example.com/about.php, than to have something complicated like example.com/index.php?about.

Instead of having a template page that grabs content, have content pages that grab their template.
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

I'd like to figure this out first. But I see where you are coming from.
I know the code was wrong, I wanted to know how to start the pagename thing.

You're saying I should have, say about.php which has include("index.php"); yes?
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

Ahh! Sam that's awesome! I've been saying that for years, but people are all gung-ho about there one-page-to-control-everything pages. I'd rather either a) use htaccess and directories or b) use seperate pages that include the template.
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

I disagree. I like to have one template that uses an include for all the content on the page. ?p=pagename works wonders for me. But it's all a matter of style I guess. Either way has it's own level of "complexity".

If you did continue on the ?page=whatever way, I'd recommend using a switch rather than if/else though.

There are pros and cons to both approaches. I'm just one of the guys who prefers includes.
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

Mr. Wiggles wrote:
You're saying I should have, say about.php which has include("index.php"); yes?


This will be easier...

?page=pagename

or, as i usually do...

?p=pagename

then have a switch, like so...

Code: [ Select ]
switch($_GET['p']){
  case page1: $page='whatchamacallit.php'; break;
  case page2: $page='whatchamacallit2.php'; break;
  case page3: $page='whatchamacallit3.php'; break;
  default: $page='home.htm'; break;
}

include($page);
  1. switch($_GET['p']){
  2.   case page1: $page='whatchamacallit.php'; break;
  3.   case page2: $page='whatchamacallit2.php'; break;
  4.   case page3: $page='whatchamacallit3.php'; break;
  5.   default: $page='home.htm'; break;
  6. }
  7. include($page);


The benefit is that the switch can carry all of your page titles, meta crap, etc. The cons is that the switch has to carry all of your page titles, meta crap, etc. Catch-22. Either way is a pain in the butt. It's all a matter of how you prefer to keep things organized. I just prefer to have everything in one file rather than in multiple.
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Your example used p and page aswell, you must have got confused. I've used p for all the vars now, so it works and I've got that idea sorted.
Now could Sam or Neksus give me an example of how to use their idea?
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

No, i was saying you can use p or page for your variable name. I always use p.
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Ok. Well that example works particularly well.
Can anyone show me the other way?
I don't know how to go about it.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 44 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.