Forum Moderators: coopster
I have a website which has over 150 pages, now presently I currently go through and change every single page. However I'm now upgrading my site design and I've read various things about PHP allowing you to create one template file which then has include commands which include the text from various other html files. Hence you only need to edit the template file to change the other 149 pages if you wanted to change the background color for instance. Is this true?
Also I cannot for the life of me find a total newbie tutorial on how to do this. I have bits and peices that I've put together but it's all getting confusing. I've tried posting all over the place but I don't get the right answers back.
I would really, really appreciate it if someone could point me in the right direction. I realise it is similiar to SSI includes but I never messed with them before either. I am solid with html but nothing else. PLEASE HELP
Second - it is absolutely possible!
Third - General resources you should become familiar with:
http://www.php.net
http://www.phpbuilder.com
http://www.mysql.com
http://www.hotscripts.com
http://www.webmonkey.com
Fourth - how to begin. You'll need to make a decision on the medium to hold the content for the 150 pages: files or a db.
The MySQL link above is all about MySQL databases - highly recommended if you go this route. In this case, you'd be querying the MySQL database for your content.
If the content doesn't need to change much and the pages aren't lengthy, then you may want to consider just using text files. In this case you would be using SSI driven by a PHP script. You could also skip the PHP in this case and just use HTML SSI.
In either case, once you've pulled in the information, you can manipulate it before you present it to screen using PHP.
Tutorials: You can find a number of tutorials on the web. PHPBuilder (link above) is a good place to start. There are plenty of others. A great book I highly recommend you purchase and read/build what they say is "PHP and MySQL Web Development" by Welling and Thomson - SAMS. Get the version with the CD - great code provided for you to use. In addition, visit http://search.hotwired.com/webmonkey/default.asp?query=php+tutorial&Submit=-%3E+GO+-%3E for a list of on-line tutorials at Webmonkey.
Play: Build something. Anything and then modify it. It's great that you have a project because it requires you to have a goal. With a little bit of digging (don't worry, you can always post here and we'll do what we can to help) you should be able to find what you need.
Hotscripts.com will provide you many free scripts for starters. Even if they don't fit exactly what you're looking for you can learn alot from what someone else built by breaking it!
Lastly, your the first link, php.net is your on-line resource for the tags used by php. You will also find user comments there on the tags. Things like what to look out for or how to use the tag.
There are many other resources out there and perhaps some of the good folks here will post them. Good luck and have fun!
G.
([1][b]edited by[/b]: lorax at 3:12 pm (utc) on May 29, 2002[/1])
main file
<?
include("./template.php");
head();
?>Place content here....
<?
tail();
?>
template.php
<?
function head(){
?>
<HTML><BODY><?
}function tail(){
?>
</body>
</html>
<?
}
?>
<HTML>
<HEAD>
<TITLE></TITLE>
<?
require_once $DOCUMENT_ROOT . "/include/header.html";
?>
put page content here
<?
require_once $DOCUMENT_ROOT . "/include/footer.html";
?>
I then edit header and footer files to do changes and meta is set on each individual page, I sometimes use a meta_generic.html and require it over the header if I have large numbers of pages that will have the same meta info.
<added>Welcome to WmW pauly
You don't actually need to use external files or a db if your pages [b]content[/b] is fairly static. On many of my pages I just do something like this:
$title="my title";
$headline=$title; // most times the same
$keywords="my key, words";
$description="my description";
$text=<<<EOF
<p>and here is my page text</p>
EOF;
then the phplib template code is just a few new functions to learn to output all your stuff into the template you've designed.
Then if you want to change something on every page, just edit the template!
...and if you really want to think ahead you can have your template parse other templates (am I going too fast?) so you'd have several files like this:
[ul][li]header
[li]body
[li]navigaion
[li]footer
[/ul]
and you only need edit certain files to change everything. If you don't see the piont, imagine you have several styles of pages but the footer is always the footer right? So you needn't edit both template_1 and template_2 just the footer.
I [b]love[/b] the phplib template class, it makes designing both small and large sites a piece of p... cake!
Nick
I stay away from absolute includes. I like my code to work on an server I throw it on. So I have a standard location I place all my global functions. Something like /www/vhosts/sharedcode/.
It takes some tweaking but once you have a template drive site down changes are super fast.
I usually have a subject or category variable. Then I have a switch statement that grabs the right meta tags. You can also make all the variables for head() parameters. I use lots of tricks like that.
Clever lady. Do you keep the tags within the file of in a db?
I stay away from absolute includes. I like my code to work on an server I throw it on. So I have a standard location I place all my global functions.
By absolute includes I assume you mean an include that holds raw code with no further decision abilities?
I totally agree on portability though I'm picky about the web hosts I use or will work with anyhow. Cuts down on erroneous glitches.
This sort of thing can be done without having to delve too deeply into the murk of PHP ;)
In the example you gave, you'd first create a simple text file containing just your <body> tag - eg:
<body bgcolor="#ffffff">
That's all you'd need in that file, and you'd save it as, for example, body.php
Next, rename your existing html pages from .html to .php, and replace the <body> tag in each page with
<?
include("body.php");
?>
This simply injects the contents of body.php into the current page at the point where you use the include() function, so if you edit body.php, the changes will effect every page in which you've used the include().
You can use as many include files as you like in a page, and even this simple technique can be a timesaver for things like navigation, page footers etc. If you want to take it further, you can use PHP code in your include file to do some funky things - but that's a different post I think ;)
I just want to thank everybody for helping me with their tips and suggested reading.
I also especially want to thank Knowles, that tutorial was a God send! I now fully understand how to implement it into my website and no longer will I have to change hundreds and hundreds of web pages just because I make a slight change.
Thanks a lot for taking time out to read and reply to this!
[url]http://www.devshed.com/Server_Side/PHP/SoothinglySeamless/page1.html[/url]
This should probably be asked in the New to Web Dev. forum but here goes anyway...In this article they mention installing these on your Linux box. Are they talking about your own actual local server (as in your a hosting service for many sites) or just a local server set-up on your regular computer?
For example, how does installing foxserv 2.1 (which installs Apache, PHP and MySQL) or PHPTriad differ from the way they want you to do it here...Which way is better?
Thanks,
M
The way it differs from the examples is those 2 packages install multipule things on your window box for a server. Where as the article is probably walking you through each peice. Its up to you on how you want to do it. I would say download one of them its faster. And IMHO I wouldnt put a production windows server running apache I would do it under linux. Hope this helps.
In this article they mention installing these on your Linux box. Are they talking about your own actual local server (as in your a hosting service for many sites) or just a local server set-up on your regular computer?
Either way, though 90% of the people reading the article are using it to set up a local testing session.
For example, how does installing foxserv 2.1 (which installs Apache, PHP and MySQL) or PHPTriad differ from the way they want you to do it here...Which way is better?
I don't know Foxserv. Triad is Windows only though isn't it? Foxserv has both versions. Basically, on a Linux machine, if you compile your own, you can specify certain options, especially for MySQL and PHP, that you won't get by default. As these apps develop though, it seems that more and more of this functionality is considered "basic" and is included in the standard binary installs, which is what you get if you use Triad, Foxserv or install from binaries on Lin or Win.
They are probably talking about a Windows machine
Nope. Windows setup is fairly straightforward by downloading the binaries.
Which way is better?
Whichever is easier for you and gets you where you want to be. On Linux, I've done both from binaries and compiling my own. With the current version, compilation isn't necessary for me. On Win, I just download the three binaries and install. I haven't tried Triad and all that. Might be great, but last I looked at it, the binaries were somewhat out of date and I wanted the same versions locally that I had on a shared server.
Tom