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

PHP

php header question

Ok having a bash at php newbie at it, i am making a site, i have managed to include headers and footers no problem, what i am stuck on is in my header.php i have a H1 tag that i would like to display a different H1 headline on different pages. i have about 10 different pages, trying to find a solution but it is a tad confusing anyone any advice or guidance?

thank you :)

2 Answers

I'm pretty sure that the best way to solve this would be set a variable before the PHP include statement on each page. This variable would have the same variable name on each page - something to the effect of :

(contact page)

<?php
$titleVariable = "contact";
include ('include/header.php'); ?>

(about us page)

<?php
$titleVariable = "about";
include ('include/header.php'); ?>

you could then either use an IF statement in the header.php that checks the $titleVariable and responds appropriately to each value or just echo out the string that the variable holds ( contact, about, etc.) depending on what you want it to display.

I'm no good explaining things and I'm new to PHP myself so this video tutorial should do a much better job of covering your needs!

Brilliant stuff thanks Spen, got a bit of homework to learn till the penny drops.