Results 1 to 2 of 2

Thread: Is a website built in sections in PHP?

  1. #1
    Join Date
    Jul 2011
    Posts
    40
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Is a website built in sections in PHP?

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

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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:
    PHP Code:
    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
       <title><?php echo "My Website Title"?></title>
    </head>
    <body>
        <h1><?php echo "Article Title"?></h1>
        <p><?php echo "Hello, World!" ?></p>
        <p>&copy; <?php echo date('Y'); ?></p>
    </body>
    </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:
    PHP Code:
    <?php
    $pagetitle 
    "My Website Title";
    $articletitle "Article Title";
    $articlecontent "Hello, World!";
    $year date('Y');

    $html '<!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
       <title>'
    .$pagetitle.'</title>
    </head>
    <body>
        <h1>'
    .$articletitle.'</h1>
        <p>'
    .$articlecontent.'</p>
        <p>&copy; '
    .$year.'</p>
    </body>
    </html>'
    ;

    print 
    $html;

    ?>
    Edit:

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

    Last edited by traq; 10-19-2011 at 06:44 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •