Results 1 to 10 of 10
  1. #1
    theomnis Guest

    Default Simple PHP Template Tutorial

    I am currently using this method on one of my sites, and I thought I would share it with you. If you have an in-depth knowledge of PHP, then this tutorial probably isnt for you, seeing as there are more efficient ways of doing the same thing. However, if you are just getting into PHP or dont know much PHP.

    The following method of using PHP templates is useful if you have alot of pages that use the same design. It makes it so that if you want to make a layout change, or change a menu in your site, you do not have to update numerous HTML files. You can simply edit one PHP file.

    Firstly, you will need a PHP file to use as a template. This will be your layout. Name it "template.php", or something else if you really want to. This is where most of the site design will be done. Simply make a layout, and then where you want the content section of the page to be, put the following PHP code:

    <?php
    include($pagename);
    ?>

    This makes it so that the section of the site you put the code in will be filled with the specified file, which in this case will be an HTML file. Also, make sure that any links to other sections of your site link to a PHP file, like "contact.php" or "downloads.php".

    You can view a sample PHP template file at http://www.gameglyph.com/template.php.

    Ok, now back to those other PHP files. Let's assume that "contact.php" will be your page. In "contact.php" put the following code:

    <?php
    $pagename = "contact.html";
    require_once("template.php");
    ?>

    This will set the variable $pagename to the corresponding HTML file which would be where you actually put the page's content. It will then load "template.php" which will see that you have defined $pagename, and load that HTML file.

    So, in conclusion, each page is made up of three files.

    PHP Template File - "template.php" - This is the general layout and unchanging areas of your site.

    PHP Page File - "contact.php" - This is the file that loads the template, and tells the template which HTML file to put in the designated content section.

    HTML Content File - "contact.html" - The corresponding HTML file that is used as the actual content of the page.

    Again, this is just a basic method. If you are using "index.php" you will either have to name the corresponding HTML file to something like "home.html" or just change your site indexing priorities to make it so that PHP index files come before HTML files. Also, if you want to use a PHP file as the content page, you can just use "contact2.php" or something to that extent.

    A functional example of this method can be seen at http://www.gameglyph.com. If you have any questions or comments, please feel free to reply.

  2. #2

    Default

    Hey theomnis! thanks a billion man.. I needed that. I know very little php and I struggle with it.

    So when you are putting that code it, you just place that strip of code where ever you want that "item" to come up at?

  3. Default

    Hmmm.. Interesting way of doing things.
    Thanks for posting it.
    And John: Yes.

  4. #4

    Default

    Okay so say you wanted to add a block to your site. You would creat the design in save it in an html file... then you'd find where you want to put it then you'd say:
    PHP Code:
    <?php
       
    include('$blocknew')
    ?>
    Is that how it would be?

  5. Default

    Im pretty new to PHP, but yeah, that looks right.

  6. #6

    Default

    Okay.. I need a lil more help. So I would put this:
    PHP Code:
    <?php (
       
    $blocknew=blocknew.html); 
    blablablablablablabla include
            (
    '$blocknew'); 
    ?>

  7. #7
    theomnis Guest

    Default

    That looks like it should work. Are you having any problems with it?

  8. #8

    Default

    Nah its workin

    Thanks pal :)

  9. Default

    Lol, there goes John always figuring stuff out

  10. #10
    fiverivers Guest

    Default

    Thanks alot for putting this message really very informatics I know very little php and I struggle with it. So please also update the code it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Parham's PHP Tutorial
    By Ardenn in forum Website Programming Discussion
    Replies: 15
    Last Post: 07-19-2012, 10:56 AM
  2. [WTS] 25 Simple Wordpress Template Collection
    By SenseiDesign in forum Templates
    Replies: 2
    Last Post: 03-16-2009, 09:13 PM
  3. Free Link Bid Script Red Template
    By temi in forum Webmaster Marketplace
    Replies: 0
    Last Post: 09-19-2008, 08:14 AM
  4. PHP template problem
    By RiverWire in forum Website Programming Discussion
    Replies: 2
    Last Post: 08-23-2007, 07:45 PM
  5. PHP Security <- A MUST READ
    By alexandru in forum Website Programming Discussion
    Replies: 0
    Last Post: 01-19-2005, 02:59 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
  •