How to Build a Contact Page on a PHP Template - dummies

How to Build a Contact Page on a PHP Template

By Steve Suehring, Janet Valade

Contact pages for websites sometimes include other elements, maybe a form or another way to interact. This means you might need to include another JavaScript file or different CSS. Luckily, you can do so by extending the PHP templating class and using that type property. Follow these steps to create the Contact page:

  1. Open classPage.php.

  2. Inside of the _getHead() method, add a conditional for a new type of page.

    The entire _getHead method should look like this:

    protected function _getHead() {
        $output = ";
        if ($this->type == "contact") {
            $output .= file_get_contents("pageHeadContact.txt");
        } else {
            $output .= file_get_contents("pageHead.txt");
        if ($this->titleExtra != ") {
            $title = $this->titleExtra . "|" . $this->title;
        } else {
            $title = $this->title;
        $output .= "<title>" . $title . "</title>";
        $output .= "</head>";
        return $output;
    } //end function _getHead()

    This code checks to see if the type property ($this->type) is set to contact. If it is, then a new <head> section file is included. Otherwise, the normal <head> section is included.

  3. Save classPage.php.

  4. Create a new empty file in your text editor.

  5. Inside of the file, add the following markup:

    <link rel="stylesheet" href="style.css" type="text/css" />
    <link rel="stylesheet" href="contact.css" type="text/css" />
    <script type="text/javascript" src=""></script>
  6. Save the file as pageHeadContact.txt in your document root.

  7. Create a new empty file in your text editor.

  8. Inside of the file, place the following CSS:

    .contactMethod {
            font-style: italic;
            font-weight: bold;
  9. Save the file as contact.css in your document root.

  10. Create a new empty file in your editor.

  11. Within the file, place the following code and HTML:

    $page = new Page();
    $page->type = "contact";
    $page->titleExtra = "Contact Me";
    print $page->getTop();
    print <<<EOF
    <div id="mainContent"> 
    <h1>Contacting me is easy</h1>
    <p class="contactMethod"></p>
    <p class="contactMethod">Twitter:  @stevesuehring</p>
    </div> <!-- end main content →
    print $page->getBottom();
  12. Save the file as contact.php in your document root.

  13. View the file in your browser


  14. Click through each link: Home, About, and Contact Me.

    The pages should work and link to each other.