homepage Welcome to WebmasterWorld Guest from 54.234.2.88
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Creating a PHP template website
How do you use PHP to create a dynamic site?
pauly




msg:1245478
 1:25 pm on May 29, 2002 (gmt 0)

Hi,

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

 

lorax




msg:1245479
 1:46 pm on May 29, 2002 (gmt 0)
First - welcome to WebmasterWorld!

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])

ukgimp




msg:1245480
 1:53 pm on May 29, 2002 (gmt 0)

This can definitely be done with ASP and using dreamweaver. The ultradev edition or now MX would be able to do a hell of a lot for you.

That said a lot of people prefer php as it is totally unrelated to MicroSnot so that can be reason in itself to opt for PHP.

Lisa




msg:1245481
 3:54 pm on May 29, 2002 (gmt 0)

Pauly,
My sites are PHP template driven. I do something like this.... You just need to edit the template.php file and all files using it show the changes.

main file

<?
include("./template.php");
head();
?>

Place content here....

<?
tail();
?>

template.php

<?
function head(){
?>
<HTML><BODY>

<?
}

function tail(){
?>
</body>
</html>
<?
}
?>


lorax




msg:1245482
 4:16 pm on May 29, 2002 (gmt 0)

Lisa,
Do you create generic meta tags to be included as well or create custom tags for each page?

jatar_k




msg:1245483
 4:30 pm on May 29, 2002 (gmt 0)

I do something like this

<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

Nick_W




msg:1245484
 4:39 pm on May 29, 2002 (gmt 0)
Hi, look up PHPLib, it's a class that is [b]seriously[/b] good for templates. I wrote somting that covers basic tutorials and setup here: [url]http://www.webmasterbase.com/article/563[/url]

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

Lisa




msg:1245485
 4:58 pm on May 29, 2002 (gmt 0)

lorax,
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. I have been refining the process for several years.

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.

lorax




msg:1245486
 6:03 pm on May 29, 2002 (gmt 0)

Hola Lisa,
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.

pauly




msg:1245487
 9:19 pm on May 29, 2002 (gmt 0)

Hey,

Thanks for all the replies but I'm still bamboozled by this. Anyone know of a simple step by step tutorial rather than just an odd bit of code here and there.

Thanks for the help so far, I just don't get it yet though :(

Paul.

sugarkane




msg:1245488
 10:38 pm on May 29, 2002 (gmt 0)

>edit the template file to change the other 149 pages if you wanted to change the background color

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 ;)

tlpretender




msg:1245489
 11:48 am on May 30, 2002 (gmt 0)

If you are in to tutorial books, I highly recommend "PHP and MySQL Web Development" by Welling and Thomson. $35 on Amazon.

mvl22




msg:1245490
 10:27 pm on Jun 7, 2002 (gmt 0)

See my post at
[webmasterworld.com...]

on a much simpler and quicker way on this issue.

Knowles




msg:1245491
 1:44 pm on Jun 9, 2002 (gmt 0)
Pauly here is a tutorial that seems fairly simple if you know PHP at all.
http://www.webreview.com/2000/02_11/developers/02_11_00_3.shtml
Not sure if that will give you what you need. I found it by doing a google search for "php template" tutorial. Hope this helps.
pauly




msg:1245492
 6:45 pm on Jun 9, 2002 (gmt 0)

Hi,

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!

Knowles




msg:1245493
 12:23 am on Jun 10, 2002 (gmt 0)

No problem Pauly glad it was what you where looking for.

madcat




msg:1245494
 10:03 pm on Jun 11, 2002 (gmt 0)
Last thing, promise...
They explain setting up PHP, Apache, etc...in this article from ergophobe.

[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

Knowles




msg:1245495
 2:21 am on Jun 12, 2002 (gmt 0)

With out reading the article I will guess at answering it cause I am fixen to head to bed. They are probably takling about a windows machine since its the most common. Normally you have no control over a hosted set up unless its dedicated not shared. Even then its up to the person hosting the server if they want to give you that much control.

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.

ergophobe




msg:1245496
 7:27 pm on Jun 17, 2002 (gmt 0)

Back from two weeks vacation...


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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved