Best way to dynamically update the content on my website

Soldato
Joined
1 Dec 2004
Posts
23,083
Location
S.Wales
Hi,

I have been developing myself a website lately using XHTML/CSS/PHP, however I want an easy way to update the content on my website, at the moment what im doing at the moment is editing each xhtml file individually with the content, ideally I would like to not have to edit the content on each page.

Please see below page for an example.

www.dmoranda.co.uk/newsite3

as you can see, the two main area's of concern are the left hand body sidebar div (this will be used as a newsfeed) I will be creating an admin page with a form that I can use to add content to this newsfeed div using PHP/CSS, storing the news in an SQL Database table - Does this seem the best way to accomplish this?

The main body div just to the right, I want to obviously add content to, but when a user selects a particular page to visit, I want the mainbody div to update? would this be the best way? otherwise I would have to go into each individual page and change the content. Also the newsfeed would be different on each page unless I kept them consistant?
 
Here is what I do. You take all content and put them into .php files. You can then include them into your content when a link is clicked. This means you only have 1 page to edit to make changes to the layout.

So in your index.php you place this:
PHP:
	<?php
	$base = './include';

	if (!isset($_GET['page']) || empty($_GET['page']))   
	{
		$file = "$base/home.php";
	}
	else
	{
		$page = preg_replace('/[\W\.-]/si', '', $_GET['page']);
		$file = "$base/$page.php";
	}

	$file = file_exists($file) ? $file : "$base/404.php";
	require $file; 

	?>

Then links will look like this:

PHP:
<a href="index.php?page=home" title="Home">Home</a>

All of the content for the homepage will be in ./include/home.php



Thanks for this, so let me get this straight, you have one main .php page (index.php) which has the above code, and the menu links, when you click on each menu link it will use the "GET Page" feature to get the content from another php page?

how is this other php page set-up?

A working example of this would be perfect (How the index.php page will look) and how the php page holding the content will look.

Thanks very much for that. :)
 
What are the pro's/con's of using PHP's get function to dynamically load page content?

I would like to know to choose which route I am going to go down.

Any help greatly appriciated.
 
Back
Top Bottom