I got this site and its based on a template as I am not into making it beautiful at this point, but more into making it work...
So Its devided to 5 parts:
Header
Left|Middle|Right
Footer
For every page the Header, Left, Right and Footer parts don't change at all [in the code that is]
So I thought making it less time consuming to make new pages by leaving the Header Left Right and Footer parts alone, and just editing the Middle...
I made this thing for the Index.php's middle section:
Code: Select all
<div id="middle">
<?php
if(isset($_GET['page']) && $_GET['page'] != NULL)
{
if(isset($_GET['ext']) && $_GET['ext'] != NULL) //Used for diffrent file types i.e: goodies.html, game.jpg, etc'.
{
$page = $_GET['page'].".".$_GET['ext'];
}
else
{
$page = $_GET['page'].".php"; //But defaults to a .php extension for convenience.
}
require $page;
}
else
{
//The actual index.php's middle code
}
?>
</div>
So I am asking if there is any good way to make what I am trying to do? The only "limit" is that the page has to be "bookmark-able"\"favorite-able".
I don't mind just adding the whole other sections of a page manually to every page on my site... I am just looking for an easier automatic way, which might also make the code more readable [Less code = Easier to find the problem].
Edit:
I also thought of stuff like separate includes for the start of the page [Header, Left, Right] and the end [Footer] so I can just include them... But I guessed its not gonna work... and also I might forget to include one of them and then go crazy at trying to understand why it give me an error...
My third idea was make a function, something like
Code: Select all
function page($page, $ext)
{
require header.php;
if(isset($ext) && $ext != NULL)
{
require $page.".".$ext;
}
else
{
require $page.".php";
}
require footer.php;
}