PHP dynamic layouts
Was wondering if someone could point me in the right direction.
My question is how can i have a static header/ footer and only the main content change. Also I want to know how i can keep the URLs SEO friendly?
One other thing is in my si开发者_开发技巧te say the section is web hosting the url i want would be http://example.com/web-hosting. No when that page loads I want there to be a side bar in the content that would be specific to web hosting and this would change depending on what top level category they are in.
If you could point me aat a tutorial or reading resource Id much appreciate it.
Thanks Dave
Without using any frameworks, what you'd do is have the code for each static segment in its own file, then include the files where appropriate in each individual page. Or, you could always just group everything into 'header.php' and 'footer.php', and include those onto every page.
If you're looking for something with a little more infrastructure, you can take a look at CodeIgniter. You'll have to read through the tutorials a bit, but it provides a framework to create each different visual block of your page once, then incorporate them into individual pages as needed.
What I do to keep header/footer same is I create a separate PHP file called pageElements
which contains functions for navigation menu, header and footer. On every page, I include that file and call those functions.
This is the simplest way, in my opinion.
I'd look into Smarty for templating your site out - I was against it but lets you seperate login from presentation.
the the url part, Apache mod_rewrite (available to most people!) will do that for you.
basic example of a .htaccess file (put in the htdocs of the site) - will re-write anyfile/path that does not physically exist:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
in your index.php (or whatever) user $_GET to access what was sent to use to direct your code.
精彩评论