PHP Inclusion
I tried alot of different methods to get this to work. Basically, you have your layout (”index.php”) and you include all of your pages into it. It is what makes addresses like index.php?p=downloads. I tried several methods until I came up with this. Note: the page you use this script on must have a .php ending!
This is your code:
<?php
$page = $_GET['p'];
switch($page)
{
case “aboutme”:
include “aboutme.php”;
break;case “downloads”:
include “downloads.php”;
break;default:
include “main.php”;
}?>
now, let’s break it down a bit.
this part;
case “downloads“:
include “downloads.php“;
break;
Is what you need to repeat for all of the pages that you’ll want to include. repace downloads with the word you want to apear after index.php?p=, I usually use the filename without the extension. Replace downloads.php with the name of your file. it doesn’t have to be a .php file, it can be .html, .htm, .txt, etc.
default:
include “main.php“;
The above is your default page. so if someone just goes to index.php without defining what page to include. You can change it to whatever should be default for your page. If it’s a blog or news feed, you may want to set it to show blog entries or news articles by default. Remember that all of your other includes need to be before this one.
That’s about it. Now, when you link to the pages, just link to them like index.php?p=downloads. Tip: If you want to link to the main page, you don’t have to go index.php?p=main, just link to index.php.
Tip!
If you want to use CuteNews and have your blog/updates displayed as default, use
default:
include “blog/show_news.php”;
where “blog” is the name of the directory cutenews is installed in.
Filed under Uncategorized |Leave a Reply

