View Full Version : Is a website built in sections in PHP?

10-19-2011, 07:42 AM
I just started out learning PHP which means I barely know what or how to code with it. I read about how to use it a while ago but only was on in the beginning haven't exactly advanced. Yesterday I started playing around with wordpress. I don't know if this has anything to do with wordpress structure or is it similiar. Does PHP break down the website into certain sections like wordpress? Or is that way off? Like I noticed there is a php file for the "head" of the page "index" or the "main"(body) of the page, footer, sidebar. I was wondering if it breaks down the webpage into parts?

If so does that mean the navigation is also on it's own php file? and basically each part of the website? And in that case if I just want to add a page would I have to make just a php file with the content and the rest will be reused(the actual web layout) or is this unique to wordpress?

I can see this being super helpful. If I don't have to make a new document for each page.(but I guess you would? but instead a new php file?)

Is it hard to learn PHP? What are some good resources on the web or books?(Do the books/websites get updated?)

10-19-2011, 06:33 PM
you've got the main ideas, but that interpretation is a little backwards:

WP uses PHP to assemble chunks of code into a single website. PHP runs first. It doesn't "break the website apart" (the website is already broken apart, in order to make it easier to manage), it "puts the website together."

To clarify a bit, WP is an example of a "Content Management System." It's code is written in php. It's a very well-developed example of what php can be used to do. The idea behind a CMS is to separate the content (articles, photos, comments, etc.) from the presentation (layout, colors, typography, display logic, etc.).

Most tutorials you find will have a "basic" example that looks something like this:
<!doctype html>
<meta charset="utf-8">
<title><?php echo "My Website Title"; ?></title>
<h1><?php echo "Article Title"; ?></h1>
<p><?php echo "Hello, World!" ?></p>
<p>&copy; <?php echo date('Y'); ?></p>
</html>This is bad, IMO, because it leads people to believe that they are putting PHP in their HTML page, which is completely untrue: they're putting HTML on their PHP page.

It's okay that the example above doesn't do anything fancy - that's not the problem. To give a clearer example of how php works, the tutorial should look more like this:
$pagetitle = "My Website Title";
$articletitle = "Article Title";
$articlecontent = "Hello, World!";
$year = date('Y');

$html = '<!doctype html>
<meta charset="utf-8">
<p>&copy; '.$year.'</p>

print $html;


As for learning resources, the best resource anywhere is the official php.net (http://php.net). And examining source code is a great way to learn, too!