Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Navigation bar - writing it only once

Hey guys, I once found a tutorial how to set up a navigation bar and header/footer only once. So in case I change sth. I only need to do it at one site and not all of them. Unfortunately I cannot find it anymore. Anybody has a link for that?

Cheers, Peter

2 Answers

Matt Campbell
Matt Campbell
9,767 Points

Hey Peter Mayer. It'll be under the PHP tutorials. I quick break down is as follows though.

  1. Save all your html files as .php files.
  2. Write a header.php and footer.php file, each containing the relevant info you want on each page's header and footer.
  3. Top of each page write <?php include('header.php'); ?>. Making sure the file you are including is in the same location, ie. root folder.
  4. Do same as 3 for footer but replacing header.php with the footer filename.

If you want to include something in a folder that's not the root folder, then it's just the same as srcing an image.

Hope that helps. :)

it does indeed. thanks a lot!!!

It will be kicking around here somewhere

http://teamtreehouse.com/library/programming/build-a-simple-php-application/creating-the-menu-and-footer/including-the-header

If not this exact video then certainly the one before or after as memory serves