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

Using variables for page titles

Hey Treehouse Folks,

So i have been updating my own website paralel to learning the "basic php application" lesson.

However i am having an issue, i have tried to set the title per a php variable, yet when i view the source code after loading the page, it hasn't echoed anything :(

The code i have at the top of each page is:

<?php $pageTitle = "AJFWeb - Home"; $section = "home"; include("inc/header.php"); ?>

and my head section in header.php is:

<head> <title><?php echo $pageTitle; ?></title> <link rel="stylesheet" href="css/normalize.css"/> <link rel="stylesheet" href="css/grid.css" /> <link href='http://fonts.googleapis.com/css?family=Inder' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/style.css" media="screen"/> <meta name="viewport" content="width=device-width"> </head>

In case it's needed, the url is www.ajfweb.com

Can someone see what i'm doing wrong? i'm sure its an obvious mistake but i can't figure it out!!!

Thanks in advance,

Aaron

7 Answers

Nikolaos Papathanassopoulos
Nikolaos Papathanassopoulos
10,322 Points

Hey Aaron,

can you post the whole 'head ... /head' section with all php in it pls? in the clientside markup on your site i cant identify where your fault is. although the 'title' tag is empty.

Still i can tell you how to do it basically.

In the header.php file you have the 'title' tag inside the 'head' tag, which should look like this:

<head>
//some <meta>
//some <style>
<title>AJFWeb - <?php echo $pageTitle; ?></title>
// i would keep this first part "AJFWeb - " 
out of your pageTitle variable. It stays static (->DRY)
</head>

~ Nikos.

If that didnt help recheck your php for missing ';'. Very often its just that. :D

Hey Nikos,

Thanks very much for your quick response, I did try and post the whole section but it appears to have got cut off, will try again with comments:

//<head> //<title><?php echo $pageTitle; ?></title> //<link rel="stylesheet" href="css/normalize.css"/> //<link rel="stylesheet" href="css/grid.css" /> //<link href='http://fonts.googleapis.com/css?family=Inder' rel='stylesheet' type='text/css'> //<link rel="stylesheet" href="css/style.css" media="screen"/> //<meta name="viewport" content="width=device-width"> //</head>

Alternatively, I have them both in my dropbox....

https://www.dropbox.com/sh/t88k1sdztjl09yp/uQ3vnyjHtI

Thanks again

Aaron

Scratch that,

Took your advice into account and dropped the "AJFWeb -" from the index.php and they are all now working!

Thanks for the quick response Nikos, yet another reason why its such a pleasure to learn with treehouse!

Cheers,

Aaron

Nikolaos Papathanassopoulos
Nikolaos Papathanassopoulos
10,322 Points

You're Welcome! ;)

Did you identify the mistake?

~ Nikos.

PS: Why is your website so "dark"?

I believe so,

I made a couple of changes at the same time, 1 being removing the AJFWeb - (maybe an "illegal character?), and the second change was retyping everything.

An issue I have found is that when uploading to my goDaddy server the changes take 20mins + to come into effect, so i may well have fixed it but not realised :)

RE the darkness i wanted something a bit different, there's lots of people out there now who have portfolio sites and will be after the same jobs that i am targeting, so i figured if i can make it memorable it might give me a (somewhat small) edge.

Do you think i should brighten it up a bit?

Nikolaos Papathanassopoulos
Nikolaos Papathanassopoulos
10,322 Points

Well, to be true, just by looking at your page i wouldnt identify it with something that you want to represent with the site. In your case the black appears on your entire screen.

Different is not always better. And one does not reduce the design of a page to just a background-color. So i guess think about what you want to display on these pages and what feeling, impression one might assign to its appearance.

make some doodles, brainstorms, associate colors?

for example:

//red is associated with aggresion, or something warm.
// blue is rather something cold, but also calming,
// green is positive, eco-friendly, "the color of hope".

There is more to this.

Just try it out. Or even ask your "Reader", friends, family and customers.

~ Nikos.

PS: just noticed: you might want to change your contactform text-color, at first i didnt see the text at all.

Ah good thinking, i never even looked that far into color schemes, just wanted something smart and different!

Contact form is in the process of being changed, I've taken to aming changes on local host now, to make sure i get it right,

Thanks for all your help Nikos, much obliged!!!