View Full Version : How to organize your site?
lsatblu
Sat 30th Sep '06, 7:36pm
Hello,
I'm not exactly sure how to ask this question, but I'll do the best I can.
On the site I am creating, I have a main css file and an index.php.
For every page that I create, they will use the same css file and layout that is in the index.php.
Is there an easier way to have each page use the same layout without putting all the code on each page, besides the content that changes?
Also, I have seen a couple sites have their content organized in folders. For example, all the about pages are in the about folder.
http://site.com/about
When you go to that address, the about page comes up. Do you think in the about folder, they have an index.php representing the about page? Or is there a better way to do this?
Lastly, I have also seen sites have an address like this.
http://site.com/?about
How do you do something like that? Or would it be better to use the folder method I asked about above?
Any help would be greatly appericated!
nico_swd
Sat 30th Sep '06, 8:18pm
Is there an easier way to have each page use the same layout without putting all the code on each page, besides the content that changes?
Templates. You might want to have a look at Smarty (http://smarty.php.net/). It depends on your site a bit though. If you have only a few pages, a template system might not be that useful.
When you go to that address, the about page comes up. Do you think in the about folder, they have an index.php representing the about page? Or is there a better way to do this?
Lastly, I have also seen sites have an address like this.
http://site.com/?about
The way HOW you store your files doesn't really matter. I'd suggest not using too long PHP URLs though, cause the search engines don't like them very much, and they're more difficult to remind for your visitors.
You can use .htaccess to "fake" the urls and make them easier to remind for your visitors and search engines. Here an example
RewriteEngine On
RewriteRule ^about\/?$ index.php?site=about
So if your original URL was site.com/?site=about, now it would be accessable via site.com/about. Much easier, huh?
How do you do something like that? Or would it be better to use the folder method I asked about above?
There are different ways.
-You can store all data in a database and call the right page using the GET variable in the URL.
-You can store all pages in a different folder (or the same) and include them depending on the GET variable.
-You can store all data in the same page and use switch() to show the wanted content only.
Which method the best is, depends on the content. If you want to have dynamic content, you're probably best off using the include method. If it's only text (longer text), I'd use a database. And if you only want to show phrases or something, I'd pick the switch() method.
I can post examples if you tell me what you want to do.
lsatblu
Sun 1st Oct '06, 12:45am
Thank you so much!
I think the storing all my pages in different folders would be the best thing.
Now I'm just going to look into using the templates that you suggested. That should make life a lot easier because I won't have to update every file when I want to change something minor.
nico_swd
Mon 2nd Oct '06, 7:15pm
If you organize your templates good, then you can use for example the header, footer and menu templates in all pages and only have to edit the one for the main content. In some cases you can even leave that and just pull different text from the database or wherever and put it in the same templates.
If you want to use the include() method, you can do something like this for example.
$pages = './pages/'; // Folder for the pages
$page = $_GET['page'] .'.php';
if (file_exists($pages . $page))
{
include($page);
}
else
{
include('error.php');
}
If you save this for example as content.php, then can you open different pages using the GET method.
content.php?page=somepage
This would include the page ./pages/somepage.php in content.php.
Late using .htaccess you can simplify this to for example ./content/somepage
vBulletin® v3.8.0 Release Candidate 1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.