treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How to get something of everypages ?

  • Hi !

    Im totally new to website design, and I have a time consuming problem.

    I have put a few things on the main page of my website (logo, the menu and some other things) and would like know how I can "copy" all this on All the pages of the website, so the update would be simultaneous (when I do)....

    Im using the hostgator tool.

    Sorry if it's not the right place for that kind of question.. :S

  • @gdumas25 You would have to use php on all the pages and use include on those pages.

    So you would create a header.php and maybe a menu.php, paste the html in those files.

    So your header.php might look something like this

      <!Doctype html>
      <html lang="en">
      <head>
          <meta charset="utf-8">
          <title>Title of Page</title><!-- You will need some php to grab the page title -->
    
          <link rel="stylesheet" href="http://yoursite.com/path/to/style.css">
    
          <script src="http://yoursite.com/path/to/script.js"></script>
      </head>
      <body>
    

    menu.php

      <nav>
          <ul>
              <li><a href="#">Home</a></li>
              <li><a href="#">About</a></li>
              <li><a href="#">Work</a></li>
              <li><a href="#">Contact</a></li>
          <ul>
      </nav>
    

    footer.php

      <footer>
        <small>&copy; 2013</small>
      </footer>
    
      </body>
      </html>
    

    From there you would just use include in your template files (about.php, contact.php or index.php if you have page folders).

      <?php include 'header.php'; ?>
      <?php include 'menu.php'; ?>
    
      <!-- All your content goes below this line -->
    
      <?php include 'footer.php'; ?>