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
Bringing content into a website
Moderator: General Moderators
Re: Bringing content into a website
You can either require the header, menu, and footer on each page.php and just put the contents on that page. e.g.
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
require 'header.php';
require 'menu.php';
echo 'this is the page here';
require 'footer.php';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 hereSet Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Bringing content into a website
Thanks for you reply. I appreciate it.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.
Or you can have everything go through the index page and pass the page as a parameter, index.php?page=aboutCode: Select all
<?php require 'header.php'; require 'menu.php'; echo 'this is the page here'; require 'footer.php';
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
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
You can also use a template rendering class or xsl
.
Re: Bringing content into a website
I've got some help from someone else and he recommended this on the page being called:
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
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
?>
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