- This topic is empty.
-
AuthorPosts
-
July 2, 2010 at 4:35 pm #29529
clockworkjordan
MemberHi,
Let me first let you know I am new here but I figured it is time I try to improve my abilities with PHP and other more complex web design tools. I am 18 and do web design as a part-time job for one or two local businesses–nothing fancy. I read css-tricks a lot but this is my first time on the forum. My experience with PHP so far has been to include the header and footer of websites, changing the date daily, and including certain variables that I like to reserve the ability to change (like a price or an address).
Today I was asked by a client to make certain pages on the website have different page titles. This would normally be a snap to do in HTML, but I have already set up this website using a system where every page has the same header file.
So My question is how do I change the page title of certain pages using php? ..Either detecting the file name and changing it that way or by letting me insert a code into the body of the text that would change the title variable?
Any help is appreciated!
The website is here: http://refinerygoldbuyers.com/
July 2, 2010 at 7:22 pm #79202ScrewzLuse
MemberThere’s definitely different ways of doing this. For me, I kind of like keeping it simple.
Page1.php
Code:Header.php
Code:My Site | Alternatively, you could have something like this in your Header.php file which checks if PageTitle is set at all and if it is, use that instead of the default "My Site"
Code:
You could do it based on the php page name itself but it’s all preference to me.
July 2, 2010 at 11:11 pm #79210clockworkjordan
MemberThis didn’t work, or at least I am not executing it correctly. Maybe it is my placement? I’m getting no title when using this method.
Let me explain more..
Basically my pages on the website work like this:index.php
Code:etc, etc…Is it bad that I have the doctype information all in the header.php file and could that be a reason this isn’t working?
Also, thank you for getting back to me so quickly!July 3, 2010 at 12:21 pm #79221Makeshift
Memberyou would need to put $pageTitle before you include the header file like this:
Code:You need to declare the variable before you try to use it.
July 8, 2010 at 5:29 pm #79402clockworkjordan
MemberOh wow. That is such a stupid mistake I didn’t catch.
Thank you so much!Now the if statement I am having a bit of trouble with. I replace this:
Code:with this:
Code:The homepage literally doesn’t show up once I enter the code, yet the page title is correct only on pages with a specific title.
Can you tell what I am doing wrong?July 8, 2010 at 10:08 pm #79441clockworkjordan
MemberOh wow, such an easy fix again. Thank you so much!
I’ve already applied this fix to page descriptions too and it works perfectly!SOLVED!
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.