Page 1 of 1
Bringing content into a website
Posted: Mon Feb 11, 2008 3:13 pm
by Jetheat
I have no clue of php but I need something done which requires it.
I have built a page with the header, left and right navigation and the footer elements.
I would like this structure to remain on every page of my site.
But in the middle of the page, I will put content depending on which links the user clicks on.
So how do I get content from my other pages into that center of my main page?
Do I load the same page everytime and call another page in the middle or do I load another page and call my main page to surround it.
What do I do and how does this work?
Appreciate the help,
JH
Re: Bringing content into a website
Posted: Mon Feb 11, 2008 4:36 pm
by s.dot
You can either require the header, menu, and footer on each page.php and just put the contents on that page. e.g.
Code: Select all
<?php
require 'header.php';
require 'menu.php';
echo 'this is the page here';
require 'footer.php';
Or you can have everything go through the index page and pass the page as a parameter, index.php?page=about
Code: Select all
<?php
//header and menu stuff here
if ($_GET['page'] == 'about')
{
require 'about.php';
} elseif ($_GET['page'] == 'contact')
{
require 'contact.php';
}
//etc
//footer stuff here
Re: Bringing content into a website
Posted: Mon Feb 11, 2008 5:45 pm
by Jetheat
scottayy wrote:You can either require the header, menu, and footer on each page.php and just put the contents on that page. e.g.
Code: Select all
<?php
require 'header.php';
require 'menu.php';
echo 'this is the page here';
require 'footer.php';
Or you can have everything go through the index page and pass the page as a parameter, index.php?page=about
Code: Select all
<?php
//header and menu stuff here
if ($_GET['page'] == 'about')
{
require 'about.php';
} elseif ($_GET['page'] == 'contact')
{
require 'contact.php';
}
//etc
//footer stuff here
Thanks for you reply. I appreciate it.
If I choose teh first option, will I be required to chop all the 4 different parts of my main page up and then include all 4 of them every time a page is requested?
Isn't there a way to save everything on the main page under one file and leave the middle empty for content?
If I choose the 2nd option will this require me to list the every single link on the site into the code on that page?
That main page has a very long navigation bar with many many links. So will I have to code for all of them on the index page?
Thanks,
JH
Re: Bringing content into a website
Posted: Mon Feb 11, 2008 5:48 pm
by dayyanb
You can also use a template rendering class or xsl

.
Re: Bringing content into a website
Posted: Tue Feb 12, 2008 2:07 am
by Jetheat
I've got some help from someone else and he recommended this on the page being called:
Code: Select all
<?php
// read the template
$template = file_get_contents("contents/template.htm");
// replace the title
$template = str_replace("{{title}}", "About Me", $template);
// generate whatever you want to display in the main part
// then
$template = str_replace("{{content}}", $content, $template);
// once everything's been replaced
echo $template;
// done, nothing else to do
?>
The question is, how do I replace $content with the contents of my page?
My 2nd question is, the main template page consists of a reference to a style.css file but when I call a page in another folder, that reference is lost.
How do I keep that reference?
Thanks,
JH