Bringing content into a website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jetheat
Forum Newbie
Posts: 4
Joined: Mon Feb 11, 2008 3:09 pm

Bringing content into a website

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Bringing content into a website

Post 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
Set 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.
Jetheat
Forum Newbie
Posts: 4
Joined: Mon Feb 11, 2008 3:09 pm

Re: Bringing content into a website

Post 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
dayyanb
Forum Commoner
Posts: 46
Joined: Wed Jan 23, 2008 12:34 am

Re: Bringing content into a website

Post by dayyanb »

You can also use a template rendering class or xsl :P .
Jetheat
Forum Newbie
Posts: 4
Joined: Mon Feb 11, 2008 3:09 pm

Re: Bringing content into a website

Post 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
Post Reply